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

QGroupBox discrepancies between Linux and Win



  • Attached two screenshots of a screen layout for part of an application that is intended fro Linux as well as for Windows. The titles for the QGroupBoxes are shown in different places. Normally one would position the title by setting the top-margin using CSS. In this case NO top-margin has been defined at all. Attached a code snippet defining one of the QGroupBoxes.

           <item row="1" column="1">
            <widget class="QGroupBox" name="groupBox_12">
             <property name="title">
              <string>Interval</string>
             </property>
             <property name="alignment">
              <set>Qt::AlignHCenter</set>
             </property>
             <property name="sizePolicy">
              <sizepolicy hsizetype="Ignored" vsizetype="Preferred">
               <horstretch>1</horstretch>
               <verstretch>0</verstretch>
              </sizepolicy>
             </property>
             <layout class="QHBoxLayout" name="diveInfoSurfintervallLayout">
              <item>
               <widget class="QLabel" name="surfaceIntervalText">
                <property name="text">
                 <string/>
                </property>
                <property name="alignment">
                 <set>Qt::AlignHCenter</set>
                </property>
               </widget>
              </item>
             </layout>
            </widget>
           </item>
    
    

    In this case the only CSS that has been added was that setting the colour of the headings.

    ui->scrollAreaWidgetContents_3->setStyleSheet("QGroupBox::title { color: mediumblue;} ");
    

    Is this between-OS difference known?
    Could it result from differences between different versions of Qt?
    Kind regards,
    Willem Ferguson



  • Windows.png
    Linux.png


  • Lifetime Qt Champion

    Hi,

    What exact OS are you talking about ?
    What version of Qt are you using ?



  • Ubuntu 18.04 LTS
    I tested with Qt5.9 and Qt5.12
    Kind regards,
    willem



  • Apologies. And Windows 7 as well as Windows 10.
    Kind regards,
    willem


  • Lifetime Qt Champion

    Can you provide a complete minimal project along your ui file ?
    That will allow to test in the exact same conditions as you have.



  • @SGaist
    Thank you for your time! This is part of a larger project and I have no idea of how to scale it down into a minimal project. I do the layout in a .ui file which started in QtCreator but I hand-edit the .ui file by hand these days. Would it help at all if I send you the complete .ui file?


  • Moderators

    @willemf said in QGroupBox discrepancies between Linux and Win:

    This is part of a larger project and I have no idea of how to scale it down into a minimal project.

    1. Make a copy of your full project.
    2. In the copied project, start removing big chunks of code and UI components that are not related to your issue.
    3. After you have removed a big chunk of code or UI, build and run the reduced code.
    4. Repeat steps #2 and #3 until the problem disappears, or until your project is tiny.

    If the problem disappears, examine the last thing that you removed.



  • @willemf
    Something like https://stackoverflow.com/questions/37233885/qt-style-windows-vs-xubuntu-gtk-no-border-in-qgropbox makes clear there are/can be differences between OS/window managers. Also that there can be deliberate "native" style differences.

    One thing to check is that you are indeed using the same style? And/or, does the difference persist if you try other styles?


  • Lifetime Qt Champion

    @JonB Yes, the alignment of the groupbox label is defined by the style.



  • Thank you very much for your responses. This explains the issue that I have been having and, fortunately, I do not have to create scaled-down minimum code for testing. I would like to explore the possibility of doing platform-dependent modification of the code by using CSS styles. I have looked everywhere but I cannot find an environmental variable within Qt that reflects the platform being used. Does anything like that exist at all? Thank you again for your time.



  • @willemf
    There won't be a run-time environment variable. I don't know of any Qt-something to indicate what platform you are on, and the platform-specific calls to determine this won't help as they are platform-specific! However, you know at compile-time which platform you are compiling for, there should be compile-time #defines for this, or if necessary you could make your qmake file pass a -D ... for this.


  • Lifetime Qt Champion

    At compile time you have the various Q_OS_XXX that allows you to encapsulate code for a specific platform.



  • @SGaist that completely answers my question. I thank you for your time in answering this.
    Kind regards,
    willem


Log in to reply