@Aleph0
Thank you very much. With your way, I can fix my issue. I just updated your code a little bit so that I still can use Fusion or Windows style.
class CustomStyle : public QProxyStyle
{
public:
CustomStyle(QString style) {
if (style == "Windows") {
m_style = QStyleFactory::create("Windows");
} else if (style == "Fusion") {
m_style = QStyleFactory::create("Fusion");
} else {
m_style = new QProxyStyle();
}
}
void drawPrimitive(PrimitiveElement element, const QStyleOption *option,
QPainter *painter, const QWidget *widget) const
{
// Disables focus drawing for a widget
if (element == QStyle::PE_FrameFocusRect) return;
m_style->drawPrimitive(element, option, painter, widget);
}
private:
QStyle* m_style;
};
auto m_tree_device = new QTreeWidget();
auto m_tree_device->setStyle(new CustomStyle("Windows"));
-- .qss file ----
// Item is selected and focused
QTreeView::item:selected:active {
background-color: #007ACC;
}
// Item is selected and unfocused
QTreeView::item:selected:!active {
background-color: lightgray;
}