Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. StyleSheet bug in Qt6.2.4
Qt 6.11 is out! See what's new in the release blog

StyleSheet bug in Qt6.2.4

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 531 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mummoc
    wrote on last edited by
    #1

    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 :)

    M 1 Reply Last reply
    0
    • M Mummoc

      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 :)

      M Offline
      M Offline
      Mummoc
      wrote on last edited by
      #2

      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.

      M 1 Reply Last reply
      0
      • M Mummoc

        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.

        M Offline
        M Offline
        Mummoc
        wrote on last edited by
        #3

        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 !

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved