首页 > 编程知识 正文

窗口缩放设置多少合适,wpf自定义控件教程

时间:2023-05-05 13:25:25 阅读:18530 作者:1169

ihavealargelogdata (100,1000,100000, records ) andiwanttovisualizeitinthefollowingmanner 3360

which构件(e.g.qlistview,QListWidget ) should I use and how,inordertostayawayfromperformanceandmemoryproblems?

Please,read about:

iwanttoshoweverylogmessageintheaboveformat

解决方案

toachievethedesiredresultandstayawayfromperformanceissues,even with a very long data log,useaqlistviewwwithacustomdelegate 3360

createasubclassofqstyleditemdelegate,say Delegate

usethecustomdelegateintheviewbycallingqabstractitemview 3360:设置删除

Example

ihavepreparedaworkingexampleforyouinordertodemonstratehowtheproposedsolutioncouldbeimplementedandusedinanapplication。

theessentialpartoftheexampleisthewaythedelegatepaintstheitemsinthelistview :

void Delegate:paint (高蜻蜓painter,constqstyleoptionviewitemoption,

常数qmodelindex索引)常数

{

初始化选项(opt,index;

constqpalettepalette (opt.palette );

constqrectrect(opt.rect;

constqrectcontentrect (rect.adjusted (m _ ptr-margins.left ) )、

m_ptr-margins.top ()、

-m_ptr-margins.right (),

-m_ptr-margins.bottom () );

constboollastindex=(index.model (-rowcount )- 1 )==index.row );

const bool hasIcon=! opt.icon.isNull (;

const int bottomEdge=rect.bottom (;

qfontf(opt.font );

f.setpoint size (m _ ptr-timestampfontpointsize ) opt.font );

painter-save (;

打印机设置剪辑(true;

打印机设置脚本(rect;

打印机设置字体(opt.font );

//绘制背景

painter-fillrect(rect,opt.state QStyle3:State宜人的小丸子/p palette.highlight ).color ) 3360

palette.light ().color ) );

//Draw bottom line

painter-set pen (最后索引? palette.dark ().color ) )。

: palette.mid ().color ) );

Pinter-drawline (最后索引? rect.left (3360 m _ ptr-margins.left )、

bottomEdge,rect.right (,bottomEdge );

//draw消息icon

if (混合) )。

painter-draw pixmap (content rect.left )、contentRect.top )、

opt.icon.pixmap(m_ptr-iconsize );

//Draw timestamp

timestamp rect.move to (m _ ptr-margins.left ) ) ) )。

m_ptr-spacingHorizontal,contentRect.top ();

打印机设置字体(f;

painter-setpen(palette.text ().color ) );

painter-drawtext(timestamprect,Qt:TextSingleLine,

index.data(Qt:3360userrole ).toString );

//draw消息文本

messagerect.move to (timestamp rect.left )、timeStampRect.bottom ) )。

m_ptr-spacingVertical;

打印机设置字体(opt.font );

painter-set pen (palette.window text ().color );

painter-drawtext (消息传递,Qt:TextSingleLine,opt.text );

painter-restore (;

}

thecompletecodeoftheexampleisavailableongithub。

结果

As written,thegivenexampleproducesthefollowingresult :

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。