Qt sidebar comes up too wide - qt

I use Qt designer (as opposed to building controls via the program) to lay out my sidebar and floating dialogs. When first launching the application, the sidebar is WAY too wide and bears no resemblance to how I saved it. The user can shrink it to a reasonable width, and that is 'remembered' after closing and re-opening the application. But it doesn't create a good first impression of our application, and not all our users are savvy enough to realize that the sidebar width can be changed.
The sidebar is quite complex, with multiple forms (QStackedWidget) and each with multiple controls. Any suggestions for forcing it to come up at the minimum width with the first use? Thanks!

You should be able to achieve the wanted behavior by setting "Horizontal Stretch" property in Qt Designer, for each of the widgets in your splitter or layout, whichever you are using to layout your components. See QSizePolicy documentation for more info.
The "Horizontal Stretch" & "Vertical Stretch" properties are located in Qt Designers Property Editor, under the sizePolicy.See the image for exact location of properties

Related

Move splitters in design mode

When i add splitters, it acts as a layout, but also allows to resize the widgets in runtime. So, for example, i managed to lay out my widgets in this way:
Therefore, i can resize my widgets in runtime. As i noticed, this function is also available in designer mode, but it doesn't work properly. I tried to hover over my splitter and drag it in designer mode, but it only replaces the entire widget.
That is how does my main window look like in QtDesigner. I haven't tried to code yet. The problem is, that even though i used to set a stretch factor, my widegt's look in designer mode and in runtime completely differ. They have another sizes.
So, what are the problems:
Firstly, i can't change my widgets sizes properly, using stretch factors. I don't know, i tried to change size policies, but i did't manage to see an effect. I have somehow changed size of the vertically oriented widgets, but when speak about horizontal orientation - stretch factor and size policy doesn't change anything at all.
Secondly, i can't move my splitter in designer mode. It's position is constant, by default, it's always somewhere in the middle.
Thirdly, i have bugs (i think so) with my widget sizes in designer mode. They differ with widget's sizes in runtime.
Question:
So, how can i change widget's sizes properly? Maybe there's a way of moving a splitter in designer mode - do newer versions of Qt have it? Currently i'm using Qt 5.9.9. Also, why these bugs, and are they bugs at all. Maybe i just should update my Qt to newer versions to get access to newer functionalities?
Comment: I'm not sure if stretch factors work with layout as they do with widgets. I'm using layouts exactly the same way i use widgets. My layout's wrong(maybe) use may have caused this problem. Anyways, i'm entirely new to Qt, and may not know something to understand it completely.

Why do custom QWidgets, but not the built-in ones, have nonzero margins?

This is a screenshot of a QFormLayout holding a series of widgets. Note that the top and bottom input widgets are not horizontally aligned to the middle two rows. Note also that the labels on the left are not vertically aligned to the middle two rows.
The difference is that the top and bottom widgets are plain QLineEdit and QTextEdit widgets, the second row is a QWidget with a QHBoxLayout holding a QSpinBox and QDateTimeEdit, and the third is a QStackedLayout containing QWidgets each with a QHBoxLayout and API-supplied widgets inside those.
It looks like these middle two have extra margins. I can (partially) improve the situation by calling QLayout::setContentsMargins on the plain QWidgets' layouts. In fact, in the image above I already have, without that it's worse.
I haven't interfered with styles in the application, it's all system-default. This seems to affect Qt5 on Ubuntu 15.04, I don't think I saw this back when it was a Qt4 application.
I tried setStyleSheet ("QWidget {margin:0;}") in the top-level widget, that introduced all sorts of problems. I also tried the variation setStyleSheet (".QWidget {margin:0;}") but that had no effect. QLayout::setSpacing also had no effect, and setting padding:0 in the stylesheet doesn't fix it either.
Nothing I've tried seems to bring the spacing around these custom-layout QWidgets in line with the API-supplied widgets.
What have I missed? Thanks.
What you observe is both the struggle of multi-platform ui and the simple fact that some widgets are horrible. Given a limited amount of time and a big task, dev teams will not treat fairly the set of features. Powerful widgets and layouts like standard widgets, QGridLayout, will be maintained day and night to be defect free while legacy widgets like QStackedWidget will be pushed at the bottom of the maintenance queue.
I tried to reproduce your issue using designer alone and here is what I got (Qt 4.8) :
What you can see:
The second line with a widget container has great marging
The third line doesn't even show the combo box (I swear it's there!!).
My two cents :
There is a difference in behavior in the second row. Because I used Qt4 and you Qt5, and we both set the QHBoxLayout margin to zero then it means there is a potential regression at play, either in Qt5 or the linux implementation. So this confirms what you suspected.
QStackedWidget is horrible. It is the usual widget provided to give quick and basic functionality rather implementing the real deal. Here it would be a widget with a QStackedLayout. Like I said I suspect those kind of widgets to receive less love when big development efforts are required.
In these situations, use QGridLayout instead of a QStackedLayout of widgets with layout of widget. It will solve the issue of labels not being aligned. Difficult to set up at first but the result is usually neat.
By the way, I switched to a widget with a stackedlayout and here is the result :

What happens to the Bottom Layout Guide when an InputView is displayed (i.e. keyboard)

So everyone loves this new Layout semantics in storyboard, it's dynamic in a way it adapts at runtime when we're inside a UINavigationController for example.
Now what about inputViews? I know inputViews are NOT part of my view, but wouldn't it make sense to affect the bottom layout guide of the containing view when a keyboard is displayed?
I mean, I've seen several coding solutions to this issue, but only one affectively takes advantage of the bottom layout guide (the others are deprecated or plain simple wrong approaches), but even that one sounds hard-wacky-coding and naturally it doesn't animate.
Is there a way to tell the view to adjust the bottom layout guide for input views automatically? I mean in storyboard? or do we need to do this sucky code let every time we use a keyboard in our application?
If the Keyboard appearing animated:YES would affect the bottom layout guide in it's progress we'd have yet another apple-is-so-cool-they-make-all-the-hard-work-for-us-while-enforcing-their-user-interface-guidelines....aff that was long :)

Fixing sizes of widgets in QT designer layouts

I have a QT form that has literally hundreds of widgets and to make them all fit on the screen at once (as required) I need to make them pretty small. The Form will have fixed (non resizable) size when used. I can resize the widgets to the desired height/width and use the appropriate (small) font size, make their size policy "fixed" etc. However, as soon as I start putting them into layouts, they gow to some, much larger minimum size. This is particularly true for the height of the widgets, but width is sometimes affectged as well.
My problem would be solved if I knew how to do one of the three following things:
Change a layout's default minimum size(s) for widgets.
Force a layout not to alter widgets sizes.
Use Qt designer to nicely align widgets in grid-like formats without using layouts.
I searched extensively Qt designer's docs and SO, to no avail.
Help is greatly appreciated
Use layouts with QWidget::setFixedSize in code (or alternative you can set the fixed size policy for each widget in designer) or you can use QLayout::setSizeConstraint

Flex/AIR layout for presentation tool (resize logic, aspect ratios etc.)

I'm developing a presentation tool for AIR (to be used together with, or as a replacement to, PowerPoint) but I'm quite a newcomer to flex layouting.
As you can see from the image, the presenter can open various apps from the main window.
Each of these apps open up in new windows which have different visual characteristics; some use the main content area to show graphics, others bullet points. Most app windows have buttons and view stacks with embedded Flash assets (using s:SpriteVisualElement).
My questions are the following:
1a. When developing a PowerPoint-like presentation tool with Flex, which layout type (basic, vertical etc.) will provide most flexibility?
1b. How do I make sure no clipping occurs on various projector screens - which aspect ratio should I have in mind?
2a. How can I resize children sprites in the SpriteVisualElement container proportionally to the window resolution?
2b. And where do I place this resize logic - on each component (sprite) with resizeHandlers or in one resizeHandler / window?
Please use the comment thread if you want me to elaborate further. Thanks.
Since you're new to Flex, I strongly reading up on the Flex Component LifeCycle.
1a. When developing a PowerPoint-like presentation tool with
Flex, which layout type (basic,
vertical etc.) will provide most
flexibility?
The layout you choose will depend on what you want to display. I don't see layouts as "Flexible". They do their job and position their elements appropriately. I can easily envision using all types of layouts in such a complicated application, each for different purposes.
1b. How do I make sure no clipping occurs on various projector screens -
which aspect ratio should I have in
mind?
I'm not quite sure I understand what this question means, but I take it to mean you want to avoid the presence of scroll bars in your app. To do that, you'll have to develop layout code that sizes and positions your children so that they do not extend past the height and width of your available content space. In Flex 3 (Halo) architecture, this would be done by writing an updateDisplayList() method for your component. In the Flex 4 (Spark) architecture, this would probably be done by writing an updateDisplayList() method for your skin class.
2a. How can I resize children sprites in the SpriteVisualElement
container proportionally to the window
resolution?
I believe my above answer already addresses this.
2b. And where do I place this resize logic - on each component
(sprite) with resizeHandlers or in one
resizeHandler / window?
In a resize handler, I would most likely use invalidateSkinState and/or invalidateDisplayList. The resizing code would be in the skin and/or updateDisplayList.

Resources