Qt-interest Archive, July 2007
Qt3 to Qt4: QTreeView change expanded decoration..?
Message 1 in thread
Hi,
I'm currently moving an application from qt3 to qt4 (4.3) and I'm trying
to convert Q3ListView based code to QTreeView with an ItemModel and an
ItemDelegate.
In qt3 i have code that changes an item decoration if it gets expanded
(pseudocode, the string represents the Pixmaps):
class BookmarkLvi : public Q3ListViewItem
...
void BookmarkLvi::setOpen(bool open)
{
if(open)
setPixmap( 0, "openend" );
else
setPixmap( 0, "closed" );
}
What's the simplest way to build this with an QTreeView and an ItemModel?
I came up with the following code but I'm not very happy with it because
i now have icon related in a delegate and the model.
Delegate:
// I'm ignoring the parameter pixmap here and simply overwrite it with
// the correct pixmap.
void drawDecoration( ... const QPixmap& pixmap ) const
{
if( option.state & QStyle::State_Open )
super::drawDecoration(painter,option,rect,"openend");
else
super::drawDecoration(painter,option,rect,"closed");
}
// unfortunately i have to return a dummy pixmap with size information
// from the model. Without it drawDecoration is not called.
Model:
QVariant BookmarkViewItemModel::data( ... )
{
...
if( role == Qt::DecorationRole )
return QPixmap(16,14);
...
}
Any better idea?
Martin
--
[ signature omitted ]