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:

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