StyleSheet bug in Qt6.2.4
-
Hi everyone !
We recently moved from Qt5 to Qt6, more specifically Qt6.2.4.
After the migration I noticed that some stylesheets were not correctly applied. More specifically adding an image on the checkboxes of a QTreeWidget.
I did some tests and noticed that this issue only seems to be present in Qt6.2.4 and not Qt6.3.1 !!
To show here's a snippet of code:MainWidget::MainWidget(QWidget *parent) : QWidget(parent) { QHBoxLayout * hLayout = new QHBoxLayout(this); this->setLayout(hLayout); QTreeWidget * tree = new QTreeWidget(this); tree->setStyleSheet("QTreeWidget::indicator {border-image: url(:/images/smile.png);}"); QTreeWidgetItem * item1 = new QTreeWidgetItem(tree); item1->setFlags(item1->flags() | Qt::ItemIsAutoTristate); item1->setCheckState(0, Qt::Unchecked); item1->setText(0, "Hello !"); QTreeWidgetItem* item2 = new QTreeWidgetItem(item1); item2->setFlags(item1->flags() | Qt::ItemIsAutoTristate); item2->setCheckState(0, Qt::Unchecked); item2->setText(0, "How are you ?"); hLayout->addWidget(tree); }
Running this code with Qt6.3.1 displays a regular QTreeWidget with my smile.png instead of the regular checkboxes. In 6.2.4 however, smile.png is nowhere to be found and the regular checkbox is shown.
Was this issue known ? What should I do to solve it, as I can't leave the checkboxes "unstyled" and we'd rather stick to Qt6.2.4 as it's the LTS version.
Thanks in advance :)
-
Hi everyone !
We recently moved from Qt5 to Qt6, more specifically Qt6.2.4.
After the migration I noticed that some stylesheets were not correctly applied. More specifically adding an image on the checkboxes of a QTreeWidget.
I did some tests and noticed that this issue only seems to be present in Qt6.2.4 and not Qt6.3.1 !!
To show here's a snippet of code:MainWidget::MainWidget(QWidget *parent) : QWidget(parent) { QHBoxLayout * hLayout = new QHBoxLayout(this); this->setLayout(hLayout); QTreeWidget * tree = new QTreeWidget(this); tree->setStyleSheet("QTreeWidget::indicator {border-image: url(:/images/smile.png);}"); QTreeWidgetItem * item1 = new QTreeWidgetItem(tree); item1->setFlags(item1->flags() | Qt::ItemIsAutoTristate); item1->setCheckState(0, Qt::Unchecked); item1->setText(0, "Hello !"); QTreeWidgetItem* item2 = new QTreeWidgetItem(item1); item2->setFlags(item1->flags() | Qt::ItemIsAutoTristate); item2->setCheckState(0, Qt::Unchecked); item2->setText(0, "How are you ?"); hLayout->addWidget(tree); }
Running this code with Qt6.3.1 displays a regular QTreeWidget with my smile.png instead of the regular checkboxes. In 6.2.4 however, smile.png is nowhere to be found and the regular checkbox is shown.
Was this issue known ? What should I do to solve it, as I can't leave the checkboxes "unstyled" and we'd rather stick to Qt6.2.4 as it's the LTS version.
Thanks in advance :)
After some research this issue has already been reported on .
(https://bugreports.qt.io/browse/QTBUG-103107?filter=-4&jql=text ~ "QTreeWidget" order by created DESC)Weirdly this report only mentions Qt5 and Qt6 but no specific subversions.
I'll try the fix advised in the report comments.
-
After some research this issue has already been reported on .
(https://bugreports.qt.io/browse/QTBUG-103107?filter=-4&jql=text ~ "QTreeWidget" order by created DESC)Weirdly this report only mentions Qt5 and Qt6 but no specific subversions.
I'll try the fix advised in the report comments.
The fix suggested in the comments works !!!
Basically for your
QTreeView::indicator { border-image: url(:/images/smile.png); }
to work properly you need to also add:
QAbstractItemView::item { background-image: url(:/images/background.png); }
In my case background.png is simply a white image.
Hope this can help someone in the future !