QGroupBox is filled with too much space.



  • Hello,

    for some reason I can't seem to make two QTextEdits (LocalIp and PublicIp) smaller. They are disproportionate.

    http://i.imgur.com/3I06clD.png

    Here's the code:

    	MyWindow.setWindowTitle("Start Game");
    	MyWindow.setCentralWidget(&MainWidget);
    	
    	ServerBox.setCheckable(true);
    	ServerBox.setChecked(false);
    	IdBox.resize(75, 20);
    	
    	ServerBoxLayout.addWidget(&IdLabel);
    	ServerBoxLayout.addWidget(&IdBox);
    	ServerBoxLayout.addWidget(&IdConnectButton);
    	ServerBox.setLayout(&ServerBoxLayout);
    	TheOneGrid.addWidget(&ServerBox, 0, 0);
    	
    	DirectLineBox.setCheckable(true);
    	DirectLineBox.setChecked(true);
    	IpBox.resize(75, 20);
    	
    	ConnectionLayout.addWidget(&IpLabel);
    	ConnectionLayout.addWidget(&IpBox);
    	ConnectionLayout.addWidget(&IpConnectButton);
    	ConnectionLayout.addWidget(&HostButton);
    	ConnectionBox.setLayout(&ConnectionLayout);
    	
    	LocalInfoLayout.addWidget(&LocalInfoLabel);
    	LocalIp.resize(75, 20);
    	LocalIp.setReadOnly(true);
    	LocalIp.setText("a");
    	LocalInfoLayout.addWidget(&LocalIp);
    	LocalInfoBox.setLayout(&LocalInfoLayout);
    	
    	PublicInfoLayout.addWidget(&PublicInfoLabel);
    	PublicIp.resize(75, 20);
    	PublicIp.setReadOnly(true);
    	PublicIp.setText("b");
    	PublicInfoLayout.addWidget(&PublicIp);
    	PublicInfoBox.setLayout(&PublicInfoLayout);
    	
    	DirectLineBoxLayout.addWidget(&ConnectionBox);
    	DirectLineBoxLayout.addWidget(&LocalInfoBox);
    	DirectLineBoxLayout.addWidget(&PublicInfoBox);
    	DirectLineBox.setLayout(&DirectLineBoxLayout);
    	TheOneGrid.addWidget(&DirectLineBox, 1, 0);
    	
    	TheOneGrid.addWidget(&HomeButton, 2, 0);
    	MainWidget.setLayout(&TheOneGrid);
    

    Any ideas what I'm doing wrong? Thanks in advance.


  • Qt Champions 2017

    Hi
    Have you tried with setMInimumHeight/Width instead of resize
    as once a widget is in a layout, then the layout controls sizes.
    But it respects Min/Max values.



  • @mrjj Thanks for your reply. I've changed LocalIp.resize(75, 20); with LocalIp.setMinimumHeight(20); but the result is the same I'm afraid :(


  • Qt Champions 2017

    @Pippin
    Well if you want it 20 , then
    LocalIp.setMaximumHeight(20)
    so at most 20.

    you could also limit the left side to prevent it from making lower box smaller



  • @mrjj Okay thanks, now I get this: http://i.imgur.com/Oyt3gnT.png

    It's better but still poorly spaced. I've tried to change the spacing of DirectLineBoxLayout but the result remains the same.


  • Qt Champions 2017

    @Pippin
    oh, hmm, it divides the area (of the container) between them.
    You could insert a VerticalSpacer to push them up.

    http://postimg.org/image/4eu5m4xy5/



  • @mrjj Ok but isn't there any way to actually reduce the area? Why does it have to be bigger than all the widgets together?


  • Qt Champions 2017

    @Pippin
    The area is also scaled to its container layout so that is where it get its height.
    maybe QLayout::setAlignment can make it stack more to the top but
    i mostly just insert a spacer.



  • @mrjj QLayout::setAlignment doesn't seem to work with DirectLineBoxLayout. I'll try to find another way.

    It sometimes is very frustrating how full of bugs Qt is.


  • Qt Champions 2017

    @Pippin
    Well you can set Maximum Height on the layout to force area smaller.

    It is possible to build using a widget as place holder.
    Have a look at this.
    https://www.dropbox.com/s/pdlb6jeph7iobc9/opper.zip?dl=0


  • Lifetime Qt Champion

    Hi,

    Maybe a silly question but since it's for IP addresses, why not use a QLineEdit ?



  • @SGaist Good point, I use QLineEdits now. My problem remains though: http://i.imgur.com/raW29vW.png

    Neither QVBoxLayout::addStretch (result is unchanged) nor QGroupBox::setMaximumHeight (result: http://i.imgur.com/FklMI9g.png) seem to work here.

    I'd rather have the extra space disappear rather than add a spacer or something. The smaller the window, the better.


  • Lifetime Qt Champion

    For the layout of your dialog, I think you should have a look at QFormLayout



  • @SGaist I can't use QFormLayouts because I need to display a Connect QPushButton as well as a Host QPushButton. Or is there a way around this?



  • Well never mind, I'll just drop the IP info so that there's no more bug.

    It is absurd how Qt has that many bugs. Before coding tip-top things, Qt's coders should make sure that the most basic (BASIC) things actually work. I wish I didn't have to use Qt. It is so very overrated. Sorry for that, but I'm both exasperated and disappointed. That's not the first unsolvable problem I've come across.


  • Lifetime Qt Champion

    You would put your QLineEdit and two QPushButton in a QHorizontalLayout. QFormLayout::addRow supports also layouts.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.