简体   繁体   中英

Different layout between Mac and Windows/Linux (same *.ui files)

I'm deploying my application with Qt Framework. The behaviour of layout is equal in Windows and Linux; and if I resize the windows the layout adapts. This doesn't happen in Mac OS. To develop for Mac, I'm using a virtual machine (the resolution is 1024x768), but, when I try to start my bundle in a "true" Mac (resolution's biggest) the result is terrible!

I put some pictures:

MAC - virtual machine (1024x768) - First tab (OK)

MAC-虚拟机(1024x768)-第一个选项卡(确定)

MAC - virtual machine (1024x768) - Second tab (Not OK)**

MAC-虚拟机(1024x768)-第二个选项卡(不正常)

**The second tab "Rubrica Contatti" is designed like the first tab "Ricettario". In designer the second tab seems ok, at runtime no!

I have tried to create a new project for test. I've set the Central Widget with Form Layout. I've created 2 Widgets that contain these items (each widget has a Grid Layout):

  • LineEdit
  • ComboBox
  • GroupBox (with Grid Layout) containing 2 labels and 2 checkboxes

All these three items are clustered in vertical layout. I put the left widget in QSizePolicy::Minimum and the right one in QSizePolicy::Preferred . In Qt Designer the left panel is smaller and the right one is horizontally enlarged. When I start the app, both widget have the same width and are in the center of the window.

Note:
When I open any project, I get this text in "General Messages" .

Warnings while parsing QML type information of /Users/denny/Qt/5.5/clang_64/qml:  
<dump of /Users/denny/Qt/5.5/clang_64/qml>:1:24: Reading only version 1.1 parts.  
<dump of /Users/denny/Qt/5.5/clang_64/qml>:10:5: Expected only Component and ModuleApi objects definitions. 

Could it be the cause?

The problem remains, but it solved so (for now)...

QApplication::setStyle("fusion");  

My app won't use Mac Themes, but it will use Fusion Theme...

Note:
The graphic is uglier, but it works!

  • For the panel on the left, set the horizontal size policies to QSizePolicy::Minimum . It means this widget can be larger but there is no point expanding it .
  • For the panel on the right, set the horizontal size policies to QSizePolicy::Preferred . It means if there is space to grow further use it .

Put the left panel widget in a single widget, the right panel widgets in another widget, and use a form layout. The form layout usually set the right size policies for left and right.

It happens because, different styles use different expanding policies. For example the QFormLayout deals with enum QFormLayout::FieldGrowthPolicy.

QFormLayout::FieldsStayAtSizeHint - This is the default for QMacStyle.

QFormLayout::AllNonFixedFieldsGrow - This is the default policy for most styles.

QFormLayout::ExpandingFieldsGrow - This is the default policy for Plastique.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM