79469294

Date: 2025-02-26 10:09:43
Score: 1
Natty:
Report link

@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;
}

Reasons:
  • Blacklisted phrase (0.5): Thank you
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @Aleph0
  • Low reputation (1):
Posted by: Tam Tran