Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Qt Academy Launch in California!

    QVBoxLayout give to much horizontal space to QTableView

    General and Desktop
    2
    8
    1643
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      epalmero last edited by

      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

      1 Reply Last reply Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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?

        1 Reply Last reply Reply Quote 0
        • E
          epalmero last edited by

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

          Sorry for the stupid question

          1 Reply Last reply Reply Quote 0
          • Chris Kawa
            Chris Kawa Moderators last edited by

            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).

            1 Reply Last reply Reply Quote 0
            • E
              epalmero last edited by

              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

              1 Reply Last reply Reply Quote 0
              • Chris Kawa
                Chris Kawa Moderators last edited by

                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.

                1 Reply Last reply Reply Quote 0
                • E
                  epalmero last edited by

                  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

                  1 Reply Last reply Reply Quote 0
                  • Chris Kawa
                    Chris Kawa Moderators last edited by

                    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.

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post