Qt学习笔记,再次分析EVA源码之后得出的结论-QListView,QListViewItem(Qt3);Q3ListView,Q3ListViewItem(Qt4)
2011-10-08 16:13
756 查看
![](http://hi.csdn.net/attachment/201110/8/0_1318061032oU3B.gif)
Qt学习笔记,再次分析EVA源码之后得出的结论-QListView,QListViewItem(Qt3);Q3ListView,Q3ListViewItem(Qt4)
今天再次分析了Eva的源码,也看了qt3中QListView和QListViewItem手册,在Eva中实现item paint的方式如下:
void EvaListViewItem::paintCell( QPainter * painter, const QColorGroup & colourGroup, int column, int width, int align ) { if( ! isVisible() ) return; if ( column == 0){ QBrush *brush; QPalette palette; EvaListView *lv = dynamic_cast<EvaListView *> (listView()); if( !lv ) return; palette = lv->viewport()->palette(); brush = 0; const BackgroundMode bgmode = lv->viewport()->backgroundMode(); const QColorGroup::ColorRole crole = QPalette::backgroundRoleFromMode( bgmode ); if ( colourGroup.brush( crole ) != lv->colorGroup().brush( crole ) ) painter->fillRect( 0, 0, width, height(), colourGroup.brush( crole ) ); else lv->paintEmptyArea( painter, QRect( 0, 0, width, height() ) ); if ( isSelected() ) { brush = new QBrush( palette.color(QPalette::Active, QColorGroup::Highlight) ); // painter->setPen( palette.color(QPalette::Active, QColorGroup::Text) ); } else { // painter->setPen( palette.color(QPalette::Normal, QColorGroup::Text) ); } int icon_width = 0; if(m_icon){ icon_width = lv->itemMargin() + m_icon->width(); } // TODO: Change the font for highlighted text m_richText->draw( painter, lv->itemMargin() + icon_width, 0, QRect( icon_width, 0, width, height() ), colourGroup, brush ); //setHeight( m_RichText->height() ); if(m_icon){ int xo = lv->itemMargin(); int yo = ( height() - m_icon->height() ) / 2; painter->drawPixmap( xo, yo, *m_icon ); } int height = m_richText->height(); if(m_icon && m_icon->height() > m_richText->height()){ height = m_icon->height(); } height += 4; setHeight( height ); widthChanged( 0 ); delete brush; } else { QListViewItem::paintCell( painter, colourGroup, column, width, align ); } }
注:上面的QListViewItem中qt4中应该改为Q3ListViewItem
再分析了Qt4中的QListWidget和QTreeWidget,得出的结论是:在qt4中qt放弃了对如Qt3中对Listview和ListViewItem的支持,在看Qt3的手册的时候可以看到:
void QListView::insertItem ( QListViewItem * i ) [virtual] Inserts item i into the list view as a top-level item. You do not need to call this unless you've called takeItem(i) or QListViewItem::takeItem(i) and need to reinsert i elsewhere.
有insertItem函数。再看看qt4中的某一个Q*Widget,比如就是QListWidget:
void QListWidget::insertItem ( int row, QListWidgetItem * item ) Inserts the item at the position in the list given by row. See also addItem().
可以看到他们就是一致的,不妨在看看QTreeWidget:
void QTreeWidget::insertTopLevelItem ( int index, QTreeWidgetItem * item ) Inserts the item at index in the top level in the view. If the item has already been inserted somewhere else it wont be inserted.
也有类似的操作。
我们知道在qt4中要像view中加入数据,就要使用qt4特有的interview框架的model/view机制。但是在qt3中向view中加入数据(item)就有直接的insert函数,在qt4中的Q*Widget也有类似的insert函数,所以:
在qt4中把qt3中类似的view的insertItem函数和class演变成了Qt4中的Q*Widget,当然他们的实现功能几乎没有太大不一样。
![](http://hi.csdn.net/attachment/201110/8/0_1318061753N94x.gif)
相关文章推荐
- Qt学习笔记,再次分析EVA源码之后得出的结论-QListView,QListViewItem(Qt3);Q3ListView,Q3ListViewItem(Qt4)
- Java集合源码学习笔记(二)ArrayList分析
- MyBatis源码学习笔记(十)SQL执行流程分析
- TensorFlow学习笔记之源码分析(2)----手写数字识别mnist example
- jQuery源码研究分析学习笔记-jQuery原型属性和方法(九)
- jQuery源码学习 item3- get()和eq()分析和对比
- 大数据学习笔记:通过源码分析mapreduce原理
- Tensorflow学习笔记参考—源码分析之最近算法
- cocos2dx内存管理机制学习笔记,源码分析
- 学习笔记之ConcurrentLinkedQueue源码分析整理
- 开源中国android客户端源码分析-学习笔记2
- tomcat源码分析学习笔记(五)
- OpenCV学习笔记(27)KAZE 算法原理与源码分析(一)非线性扩散滤波
- JFinal个人学习笔记之源码分析2
- QT学习笔记之QT5 + VS2013/VS2015 中文乱码解决办法以及ListView,TableView,TreeView的基本用法
- java学习笔记-String源码分析(2)
- Openstack学习笔记之——Neutron-server服务加载与启动源码分析(三)
- 深入分析JavaWeb Item26 -- MySQL 学习笔记
- Python爬虫框架Scrapy 学习笔记 7------- scrapy.Item源码剖析
- 安卓学习笔记---ListView选择服务机构,选择完之后可以显示当前的选择项