Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Controls with listboxes differ between "vista" and "fusion" style?



  • Hello,

    I like to port my Qt 5.15/16.0 Windows application to Linux. On Windows 10 Qt defaults to "windowsvista" application style - alternative there's "fusion" style available. On Linux Qt defaults to the "fusion" style - there's no other application style available.

    Since the first time I saw my application on Linux I'm confused. Because QComboxBox in comparison with other control-widgets that have listboxes like QListWidget doesn't have equally sized item/menu heights anymore. Scaling doesn't affect this situation:

    alt text

    As you can see in Windows "vista" style both controls have exact the same item/menu height. But in "fusion" style the item/menu height of QComboBox gets much larger and at the same time the item/menu height of QListWidget smaller. That even gets worse using the "fusion" style on Linux.

    Here's my code. Because Linux and Windows use different default fonts the Roboto font is used for better comparison:

    #include <QApplication>
    #include <QWidget>
    #include <QStringList>
    #include <QLabel>
    #include <QComboBox>
    #include <QListWidget>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QWidget w;
    
        QLabel labelCombo(&w);
        labelCombo.setFont(QFont("Roboto", 9));
        labelCombo.setText("QComboBox");
        labelCombo.setGeometry(24, 10, 90, 20);
    
        QLabel labelList(&w);
        labelList.setFont(QFont("Roboto", 9));
        labelList.setText("QListWidget");
        labelList.setGeometry(164, 10, 90, 20);
    
        QStringList stringList;
        for (int i=1; i<=20; i++) {
            QString string = QString("Item%1").arg(i);
            stringList.append(string);
        }
    
        QComboBox combo(&w);
        combo.setFont(QFont("Roboto", 9));
        combo.setGeometry(20, 30, 120, 25);
        combo.addItems(stringList);
        combo.setMaxVisibleItems(22);
    
        QListWidget list(&w);
        list.setFont(QFont("Roboto", 9));
        list.setGeometry(160, 30, 120, 344);
        list.addItems(stringList);
    
        w.resize(300,480);
        w.show();
        return a.exec();
    }
    

    Because I couldn't find any complains about this issue in the internet I wonder if there might be something wrong with my code?

    How to make all control-widgets that got listboxes look more uniform on Linux? Like it's on Windows 10 with it's default "vista" style?

    Best regards,
    mireiner


  • Lifetime Qt Champion

    It's all fine. The style is responsible on how to draw the widgets and the fusion style uses some larger elements.



  • @Christian-Ehrlicher said in Controls with listboxes differ between "vista" and "fusion" style?:

    It's all fine. The style is responsible on how to draw the widgets and the fusion style uses some larger elements.

    Hello Christian,

    sorry - the "fusion" style proportions between QComboxBox and QListWiget in this example doesn't look right to me eyes.

    On Windows 10 the proportions of both control-widgets look absolutely fine. How to achieve the same uniform proportions on Linux?


  • Lifetime Qt Champion

    They are correct. On fusion they're different.



  • @Christian-Ehrlicher said in Controls with listboxes differ between "vista" and "fusion" style?:

    They are correct. On fusion they're different.

    I understand that fusion style looks different. That's absolutely fine. The same if both controls would have equally larger sizes.

    The problem is the different item/menu heights of both controls. In fusion style they lose their equal size considerably. One is too large the other too small.


  • Lifetime Qt Champion

    @mireiner Fusion style has different height for those two controls. Use a custom style or QProxyStyle if you don't like it.



  • Sorry but still my personal opinion is that the larger QComboBox dimensions in fusion style is not correct und should be fixed. Expecially on Linux where fusion style is the only application style available.

    Meanwhile I found out a workaround for this issue. But don't quite understand how it works. If you change the combobox-popup style:

    comboBox->setStyleSheet("combobox-popup: 0;");
    

    The problem is gone that QComboBox dimensions are too large. And the whole QComboBox has exact the same size as QListWidget and QTreeWidget. The code works also inside Qt Designer adding following line to the stylesheet parameter of each QComboBox:

    QComboBox { combobox-popup: 0; }
    

    On other hand if you change the style to:

    comboBox->setStyleSheet("combobox-popup: 1;");
    

    The problem is back again. So the parameter "1" might stand for fusion style. But what is parameter "0" standing for on Linux? I wasn't able yet to find anything about it in the Qt documentation.

    Does this mean that the QCombobox fusion style dimension problem might be caused by a wrong internal combox-popup stylesheet assignment? To clear this question I wrote the following bug report: https://bugreports.qt.io/browse/QTBUG-89037


Log in to reply