QVBoxLayout give to much horizontal space to QTableView



  • Dear All:

    I am trying to Layout a QWidget that contain a QTableView a QPushButton, for that I am using a QVBoxLayout the problem I am having is that the QVBoxLayout is to big for the size of QTableView. I will expect the QVBoxLayout to be able to fit to the QTableView size but I am having a lot of space horizontally.

    The code I am using is as follow:

    @/ Create the Objects in the Dialog
    channelSelectionList_ = new TraceOverlayChannelSelectionList(channels, targetChannelId);

    closeButton_ = new QPushButton(tr("&Finish"));
    connect(closeButton_, SIGNAL(clicked()), this, SLOT(finished_()));
    
    // Layout Objects
    QVBoxLayout *layout = new QVBoxLayout;
    layout->addWidget(channelSelectionList_);
    layout->addWidget(closeButton_);
    setLayout(layout);
    

    @

    Thanks a lot for any help I can get
    Ernesto


  • Moderators

    bq. the QVBoxLayout is to big for the size of QTableView.

    What do you mean by that? QTableView is positioned and sized using the layout, so what do you mean it's too big for size?

    bq. I will expect the QVBoxLayout to be able to fit to the QTableView size but I am having a lot of space horizontally.

    The layout is not inside the table view. It doesn't fit anything. It lays out widgets assigned to it. Where exactly is the space? Can you describe what you're getting and what you want a little more? Or show a picture of expected result?



  • Sorry can you please tell me how to add a picture here.

    Sorry for the stupid question


  • Moderators

    Sure, unfortunately this forum does not host pictures directly. You need to upload it to some external hosting site like tinypic.com or photobucket.com. Then copy the link they generate and paste here using the photo button (around the middle of the button bar above the text).



  • Thanks a lot please find here the link with the image. As you can see the horizontal width of the QWidget holding the QTableView is to big.

    https://dl.dropboxusercontent.com/u/64570880/Capture.JPG

    All the best and thanks again
    Ernesto


  • Moderators

    Sorry, but I don't get it. It looks ok to me.

    If you mean the space to the left and right, outside of the table then these are margins controlled by "setContentsMargins":http://doc.qt.io/qt-5/qlayout.html#setContentsMargins method of the layout. Set them to 0 or whatever you want.

    If you mean the white space inside the table then if you want to set the table to specific width you can use its method "setFixedWidth":http://doc.qt.io/qt-5/qwidget.html#setFixedWidth for that.



  • I have update the image with a red rectangle where I think the space should not be there. For me the QVBoxLayout should remove all that empty space.

    Thanks
    Ernesto


  • Moderators

    It's a vertical layout so it only manages the vertical size of the widgets. In horizontal axis they get as much space as there is, unless they specify a maximum amount they can use.
    For that you can use either the setFixedWidth method I mentioned or setMaximumWidth if you want to let it shrink.


Log in to reply
 

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