PDA

View Full Version : QTreeWidget and keep "focus drawing" every time



Lykurg
3rd April 2008, 17:04
Hi,

what I want achieve is that a checked item in a QTreeWidget which has lost focus is displayed as it has focus. A checked item in a focused QTreeWidget has - on my desktop - a blue background, but every time i focus any other element in my application the item is still checked, but gets a withe background. That I want avoid.

What I have done so far:


Create a custom style with
void myStyle::drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const
{
if (!(element == QStyle::PE_FrameFocusRect && widget->objectName() == "files"))
QCleanlooksStyle::drawPrimitive(element, option, painter, widget);
} to hide ugly focus rectangle of the items. ("files" is the name of my QTreeWidget)
Forbit that a selection is cleared
void XmlFileSelector::slot_currentItemChanged(QTreeWidg etItem *current, QTreeWidgetItem *previous)
{
if (current)
// do some stuff...
else
ui.files->setCurrentItem(previous);
}
always draw selection background for the items.
??? I don't have any idea to achieve that. Must that done in my costum style?



Thanks
Lykurg