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

Line under radio Button and Button sizing in a Layout



  • Hi there,
    i started to play around with QT Creator and put together a small GUI for a piece of Test software. I used the "design" functionality and "drag and drop" to create the project so far and i came across two points i seem not to be able to solve on my own.
    The first one is a very thin line appearing under one of the radio buttons which i don't know where it comes from and how to get rid of it.

    Bildschirmfoto von 2021-04-03 11-58-03.png

    The second one is that i cant resize the PushButtons in the lower right ("Start Test" / "Reset Config"), the option to change their size gets greyed out as soon as i put them into the layout box. How can i resize them? At last here is the head of my system info. I currently see no way to upload my whole project but i would if necessary.

    Qt 5.15.2 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 5.3.1 20160406 (Red Hat 5.3.1-6)) on "xcb" 
    OS: Ubuntu 20.04.2 LTS [linux version 5.8.0-48-generic]
    

    Thanks in advance for any assistance.


  • Lifetime Qt Champion

    Hi and welcome to the forums

    That strange line. Is it listed to the right in Design mode ?
    (there is a widget tree shown)
    It looks like a normal horzLine widget. but hard to say.

    When a widget is added to a layout, its size and location is handled by the layout.
    To affect its size, you can specify min and/or max size for the widget amoung other things.
    alt text

    So to resize your button, you can set its minimum size so the layout allows/follows this.
    https://doc.qt.io/qt-5/layout.html



  • Hi @mrjj :)
    thank you for helping me out. I succeeded to change the "minimum height" of the Button , i could swear i searched there at least twice before but i must have overlooked it. Derpy me.
    The line does not appear in my Design tree, but i snipped it so you can have a look for yourself.
    Bildschirmfoto von 2021-04-03 14-22-15.png
    It is also only visible when i run/build the code.



  • @Detzi

    Your centralWidget does not have any layout :) You should fix this to avoid further layout issues :)
    (Also both of your QGroupBoxes)

    Your layouts are inside your boxes but not applied to them.



  • @Pl45m4 do you mean like this?
    Bildschirmfoto von 2021-04-03 18-38-56.png

    I think i figured out what the line is/was, it seems to be the border line of the RadioButton Box.



  • @Detzi

    Still no layout (as you can see from the red crossed signs next to your centralWidget and your two GroupBoxes).
    Delete the layouts inside these containers (verticalLayout_4, _5 and _6), assign a layout to them (Right-click -> Layout...) and add your content again.

    Edit:
    Actually you have to add content first, before you can assign a layout, so delete your verticalLayouts, put content back in and then assign a layout.



  • @Pl45m4
    I think i got it this time
    Bildschirmfoto von 2021-04-04 08-12-24.png

    Although i don't understand how this is beneficial. I tried to read up why this is good practice here:
    Qt Documentation: Layout Management but it seems not to talk about this.
    Also for horizontalLayout_4 does it matter that it is a Layout container or should i rather use a group box and assign a Layout?



  • @Detzi said in Line under radio Button and Button sizing in a Layout:

    should i rather use a group box and assign a Layout?

    A standard layout should be enough.
    You don't need QGroupBoxes frame and title functionality there.QGroupBox fits perfectly in your case above, where you want to group things up (like your RadioButtons) and maybe give them a title/header. QGroupBox also provides the possibilty to check/uncheck the whole box to enable/disable its content. You really dont need that for 2 simple buttons and 2 spacers (at least not in your use case).

    @Detzi said in Line under radio Button and Button sizing in a Layout:

    Although i don't understand how this is beneficial. I tried to read up why this is good practice here:

    Make a new (Test)-project, skip the layout part and add random stuff. Then run your program and resize your window :)
    You will see a huge difference in the resize / layout behavior of your widgets, esp. when you compare it with your current or any other project, that uses layouts correctly.
    With layouts everything looks clean and resizes properly.



  • I think i understand. Thank you both very much for your time and effort.


  • Lifetime Qt Champion

    @Detzi
    Hi
    Well the red layouts are meant to be used to sub divide another layout
    and it not used as base layout as they float if not put in a layout.
    So normally we apply a layout by right-click the widget and use the layout menu.


Log in to reply