[Qt-interest] Setting item border by stylesheets disable custom item's background in QTreeView
Daniele Esposti
expo at expobrain.net
Mon Sep 12 14:55:30 CEST 2011
In a QTreeView which displays custom items the item's background
defined by code is ignored if a border is applied to the items by
stylesheets.
Here the snipped of code which returns the item's background:
QVariant Item::data(int role = Qt::UserRole + 1) const
{
if (role==Qt::BackgroundRole) {
return QBrush(Qt::red);
}
return QStandardItem::data(role);
}
In the main view, setting this style sheet shows the item's border but
ignore the custom item's background:
tree->setStyleSheet("QTreeView::item { border: 1px solid green; }");
Tested on Mac OS X Lion and Windows 7 with Qt 4.7.4. I've also
attached the source code of a small example to reproduce the problem.
--
Daniele Esposti
My Blog http://www.expobrain.net
LinkedIn http://www.linkedin.com/in/danieleesposti
Twitter http://www.twitter.com/#!/expobrain
-------------- next part --------------
A non-text attachment was scrubbed...
Name: item.cpp
Type: text/x-c++src
Size: 268 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110912/faecf9fd/attachment.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: item.h
Type: text/x-chdr
Size: 167 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110912/faecf9fd/attachment-0001.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.cpp
Type: text/x-c++src
Size: 177 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110912/faecf9fd/attachment-0002.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mainwindow.cpp
Type: text/x-c++src
Size: 739 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110912/faecf9fd/attachment-0003.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mainwindow.h
Type: text/x-chdr
Size: 198 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110912/faecf9fd/attachment-0004.bin
More information about the Qt-interest-old
mailing list