Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] help with layout
QtWS25 Last Chance

[SOLVED] help with layout

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 3.0k Views
  • 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.
  • F Offline
    F Offline
    fluca1978
    wrote on last edited by
    #1

    Hi,
    in a widget I've got the following layout setup:

    @QHBoxLayout* hLayout = new QHBoxLayout( this );
    panelMaster->setLayout( hLayout );
    tableViewMaster->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
    hLayout->addWidget( tableViewMaster );

    QWidget* buttons = new QWidget( this );
    QVBoxLayout* vLayout = new QVBoxLayout( buttons );
    buttons->setLayout( vLayout );
    vLayout->addWidget( buttonAddMasterElement );
    vLayout->addWidget( buttonEditMasterElement );
    vLayout->addWidget( buttonDeleteMasterElement );
    vLayout->addWidget( buttonRefreshMasterElement );
    hLayout->addWidget( buttons );
    

    @

    The idea is to have the tableview to occupy the most and central space of the widget, with a vertical set of buttons on the right. However, when I set up this widget as the central widget of my mainwindow the widget itself occupies less than the whole window space and I cannot resize the table. What am I doing wrong?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      It's a bit difficult to say, what is wrong, as I have no idea, how the widgets belong to each other (parent child). What is the panelMaster pointer? Where is tableViewMaster created on?

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fluca1978
        wrote on last edited by
        #3

        Well the method that performs the setup of the gui from the constructor of the widget (and the constructor does nothing else) is:

        @
        void UserView::setUpPanelMaster()
        {
        panelMaster = new QWidget( this );
        ...
        tableViewMaster = new QTableView( panelMaster );

        ...
        QHBoxLayout* hLayout = new QHBoxLayout( panelMaster );
        panelMaster->setLayout( hLayout );
        tableViewMaster->setSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding);
        hLayout->addWidget( tableViewMaster );
        
        
        
        QWidget* buttons = new QWidget( panelMaster );
        QVBoxLayout* vLayout = new QVBoxLayout( buttons );
        buttons->setLayout( vLayout );
        vLayout->addWidget( buttonAddMasterElement );
        vLayout->addWidget( buttonEditMasterElement );
        vLayout->addWidget( buttonDeleteMasterElement );
        vLayout->addWidget( buttonRefreshMasterTable );
        hLayout->addWidget( buttons );
        

        @

        I think I fixed all the paret-child relationships.
        In the mainwindow I've got:

        @setCentralWidget( uview );@

        with uview as my widget and no layout set up for the main window.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #4

          And where is the layout of uview?
          What is panelMaster used for? In which layout is it used?
          Or is userView the main window class?

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • F Offline
            F Offline
            fluca1978
            wrote on last edited by
            #5

            To make it clear:

            • uview is a subclass of QWidget that in its constructor calls setUpPanelMaster:

            @UserView::UserView(QWidget *parent) :
            QWidget(parent)
            {

                setUpPanelMaster();
            

            }@

            • panel master is simply used as a panel within uview, since I will reach the condition when I have two or more panels with different widgets inside the uview (but at the moment I'm using only one).
            • panel master is set up with a horizontal layout, on the left there is the tableview, and on the right there is vertical layout with the buttons.
            • in the main window class I create a new uiview and place it as central widget without any further layout setup.
            1 Reply Last reply
            0
            • F Offline
              F Offline
              fluca1978
              wrote on last edited by
              #6

              I managed it in the end!
              The problem was in the constructor of the UserView, that while it was setting up a layout, it was not adding widgets to it. The final code that works is therefore:

              @// set up a vertical layout
              QVBoxLayout* vLayoutMain = new QVBoxLayout( this );
              setLayout( vLayoutMain );

                  setUpPanelMaster();
              
              
                  vLayoutMain->addWidget( panelMaster );
              

              @

              and now it is displayed correctly.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved