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. [SOLVED] Mac OSX 'basiclayouts' example behaving differently than Windows version
QtWS25 Last Chance

[SOLVED] Mac OSX 'basiclayouts' example behaving differently than Windows version

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.7k 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.
  • J Offline
    J Offline
    janalleman
    wrote on last edited by janalleman
    #1

    New to Qt, and trying to work through examples to verify the cross platform capability to determine if our company's next project would benefit from this.
    Found a discrepancy between Mac OSX and Windows....the basiclayouts example place a QFormLayout on the main window. On Windows 7 system the dialog initialize and stretch the QFormLayout to view width, and then resize the layout correctly when resizing the window. On Mac OSX it does not perform the same way. It initialize to some fixed width and center in the view, then on view resize it keeps the same width and only moves the QFormLayout to stay in center without trying to resize.
    I tried to fix with size policy (didn't work), also tried a containing widget with QVBoxLayout (didn't work either).
    How can this example code be adapted to make the Mac version resize similar to the Windows version?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      QFormLayout respects the platform defaults.
      Windows and OSX define different default values and criteria for Form Layout.

      As a general rule Qt uses defaults values for layouts and other things (like the order of buttons in standard dialogs, standard icons, ...) coming from the Platform where the application is executed. In this way the application will be better integrated in the environment where runs.

      Anyway you can always force these settings to the values you need.

      If you can't specify unique values for different platforms you can always (but only if is really needed) use #ifdef statement based on the platform like:

      #ifdef Q_OS_WIN
      // Windows specific
      
      #elif Q_OS_DARWIN
      // OSX
      
      #elif Q_OS_LINUX
      // Linux
      
      #endif
      

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      J 1 Reply Last reply
      0
      • M mcosta

        Hi,

        QFormLayout respects the platform defaults.
        Windows and OSX define different default values and criteria for Form Layout.

        As a general rule Qt uses defaults values for layouts and other things (like the order of buttons in standard dialogs, standard icons, ...) coming from the Platform where the application is executed. In this way the application will be better integrated in the environment where runs.

        Anyway you can always force these settings to the values you need.

        If you can't specify unique values for different platforms you can always (but only if is really needed) use #ifdef statement based on the platform like:

        #ifdef Q_OS_WIN
        // Windows specific
        
        #elif Q_OS_DARWIN
        // OSX
        
        #elif Q_OS_LINUX
        // Linux
        
        #endif
        
        J Offline
        J Offline
        janalleman
        wrote on last edited by
        #3

        @mcosta Thank you for the quick reply
        How would one force the default settings....recompile Qt from source?
        Regarding your #ifdef suggestion, does this mean for Mac I should rather use grid view and manually build a view that resembles the Windows version of QFormView?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcosta
          wrote on last edited by
          #4

          Hi,

          you can change the settings for a QFormLayout using the properties fieldGrowthPolicy, formAlignment, labelAlignment (as you can read in the documentation they have different values depending of the plaftorm).

          If you want to override the default settings (the same values each time you use a QFormLayout) you can write your ownQStyle and apply it to your application.

          About the #ifdef; I mean you could set different values for a property depending on the platform. Example

          #ifdef Q_OS_WIN
              layout-> setFormAlignment(Qt::AlignLeft| Qt::AlignTop);
          #else
              layout-> setFormAlignment(Qt::AlignRight| Qt::AlignTop);
          #endif
          

          NOTE: In my experience it's better to use the platform standard values because the interface will be more familiar to the final user.

          Once your problem is solved don't forget to:

          • Mark the thread as SOLVED using the Topic Tool menu
          • Vote up the answer(s) that helped you to solve the issue

          You can embed images using (http://imgur.com/) or (http://postimage.org/)

          J 1 Reply Last reply
          1
          • M mcosta

            Hi,

            you can change the settings for a QFormLayout using the properties fieldGrowthPolicy, formAlignment, labelAlignment (as you can read in the documentation they have different values depending of the plaftorm).

            If you want to override the default settings (the same values each time you use a QFormLayout) you can write your ownQStyle and apply it to your application.

            About the #ifdef; I mean you could set different values for a property depending on the platform. Example

            #ifdef Q_OS_WIN
                layout-> setFormAlignment(Qt::AlignLeft| Qt::AlignTop);
            #else
                layout-> setFormAlignment(Qt::AlignRight| Qt::AlignTop);
            #endif
            

            NOTE: In my experience it's better to use the platform standard values because the interface will be more familiar to the final user.

            J Offline
            J Offline
            janalleman
            wrote on last edited by
            #5

            @mcosta Thank you!
            The magic happened with
            layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);

            M 1 Reply Last reply
            1
            • J janalleman

              @mcosta Thank you!
              The magic happened with
              layout->setFieldGrowthPolicy(QFormLayout::AllNonFixedFieldsGrow);

              M Offline
              M Offline
              mcosta
              wrote on last edited by
              #6

              @janalleman said:

              @mcosta Thank you!

              You're Welcome.

              Happy programming and enjoy Qt

              Once your problem is solved don't forget to:

              • Mark the thread as SOLVED using the Topic Tool menu
              • Vote up the answer(s) that helped you to solve the issue

              You can embed images using (http://imgur.com/) or (http://postimage.org/)

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                If I may add Q_OS_OSX is the define to use when doing Max OS X specific stuff

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                M 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  If I may add Q_OS_OSX is the define to use when doing Max OS X specific stuff

                  M Offline
                  M Offline
                  mcosta
                  wrote on last edited by
                  #8

                  @SGaist You're right.

                  Sorry, In our project we use Q_OSX_DARWIN because we run also on iOS

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  1 Reply Last reply
                  0

                  • Login

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