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. QTreeWidget item font is different if going over widget width
Forum Updated to NodeBB v4.3 + New Features

QTreeWidget item font is different if going over widget width

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 985 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.
  • P Offline
    P Offline
    Pauly
    wrote on 4 Jun 2019, 05:19 last edited by
    #1

    In a QTreeWidget, item font is different for those going over the widget width. What is going on and how can I fix it? Also for some reason the last decoration icon is different from others. I don't think I make any changes to QTreeWidget but not sure, where should I look to make these look alike? Thank you.

    0_1559625433306_364297d5-a359-42ae-82ef-ddc61f167189-image.png

    J 1 Reply Last reply 4 Jun 2019, 08:00
    0
    • P Pauly
      4 Jun 2019, 05:19

      In a QTreeWidget, item font is different for those going over the widget width. What is going on and how can I fix it? Also for some reason the last decoration icon is different from others. I don't think I make any changes to QTreeWidget but not sure, where should I look to make these look alike? Thank you.

      0_1559625433306_364297d5-a359-42ae-82ef-ddc61f167189-image.png

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 4 Jun 2019, 08:00 last edited by J.Hilk 6 Apr 2019, 15:59
      #2

      @Pauly

      seems strange but without actual code, no-one will really be able to help you.

      Do you have a minimal compile-able example at hand?


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • V Offline
        V Offline
        VRonin
        wrote on 4 Jun 2019, 08:45 last edited by
        #3

        Are you using a stylesheet or a custom style?

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        1
        • P Offline
          P Offline
          Pauly
          wrote on 5 Jun 2019, 04:07 last edited by
          #4

          Here is the code. It is pretty straightforward that I just put a list of QStringList into the tree widget, which is added in designer. No stylesheet etc was set.

          The original post shows child items, but this happen to top level items too. Whenever the item is longer than the widget width, the font of item will be different. I try to put text in QLabel then set that to tree widget, then the font will be the same. However I think we should not need to go the extra step to make tree widget behave... any advise? Thanks.

          ui->setupUi(this);
          QList<QStringList> msg;
          for(int i=0;i<msg.size();++i){
              if(msg.at(i).size()>0){
                  QTreeWidgetItem * topLevel = new QTreeWidgetItem();
                  topLevel->setText(0, msg.at(i).at(0));
                  ui->myTreeWidget->addTopLevelItem(topLevel);
                  for(int j=1;j<msg.at(i).size();++j){
                      QTreeWidgetItem * item = new QTreeWidgetItem();
                      item->setText(0,msg.at(i).at(j));
                      topLevel->addChild(item);
                  }
              }
          }
          ui->myTreeWidget->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
          show();
          
          1 Reply Last reply
          0
          • C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 5 Jun 2019, 04:55 last edited by
            #5

            Which Qt version do you use? It was fixed in 5.12

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            4
            • P Offline
              P Offline
              Pauly
              wrote on 10 Jun 2019, 06:06 last edited by
              #6

              I'm using

              Qt Creator 4.8.2
              Based on Qt 5.12.1 (MSVC 2015, 32 bit)

              should I upgrade? Thanks.

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 10 Jun 2019, 07:12 last edited by
                #7

                I don't want to know what QtCreator you're using but what Qt version you're using to build your programs. It needs to be at least 5.12.2: https://bugreports.qt.io/browse/QTBUG-56759

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                1 Reply Last reply
                2
                • P Offline
                  P Offline
                  Pauly
                  wrote on 12 Jun 2019, 05:11 last edited by
                  #8

                  I see. Thanks for the note.

                  Also I found that doing "setFont(QApplication::font());" fixes the issue.

                  1 Reply Last reply
                  0

                  2/8

                  4 Jun 2019, 08:00

                  6 unread
                  • Login

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