⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

QTreeWidget item font is different if going over widget width

  • 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.


  • Moderators


    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?

  • Are you using a stylesheet or a custom style?

  • 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.

    QList<QStringList> msg;
    for(int i=0;i<msg.size();++i){
            QTreeWidgetItem * topLevel = new QTreeWidgetItem();
            topLevel->setText(0, msg.at(i).at(0));
            for(int j=1;j<msg.at(i).size();++j){
                QTreeWidgetItem * item = new QTreeWidgetItem();

  • Lifetime Qt Champion

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

  • I'm using

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

    should I upgrade? Thanks.

  • Lifetime Qt Champion

    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

  • I see. Thanks for the note.

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

Log in to reply