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. QTableview not fitting the entire dockwidget window
QtWS25 Last Chance

QTableview not fitting the entire dockwidget window

Scheduled Pinned Locked Moved Solved General and Desktop
28 Posts 3 Posters 9.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.
  • S Offline
    S Offline
    saitej
    wrote on 13 Apr 2016, 13:45 last edited by
    #1

    This code generates a tableview for a docked window as shown in image 1 but I want a tableview as shown in image 2. (second image tableview was generated on mainwindow using setCentralWidget(widget); ). When I try to use the same code , i get the error 'setCentralwidget' not declared in this scope as it is not mainwindow. How to get the similar view for a docked window?

     ui->deleteButton->setEnabled(false);
        ui->tableView->setModel(model);
        ui->tableView->setItemDelegate(new ItemDelegate(this));
        ui->tableView->verticalHeader()->setDefaultAlignment(Qt::AlignVCenter | Qt::AlignRight);
        ui->tableView->horizontalHeader()->setStretchLastSection(true);
        ui->tableView->resizeColumnsToContents();
    
    
        ui->tableView->verticalHeader()->setSectionsMovable(true);
    
        ui->addButton->setFocus();
    
    

    image1
    image2

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 13 Apr 2016, 14:07 last edited by
      #2

      @saitej said:
      hi for a docked window, you would add a
      layout to it first and then insert the controls
      in that layout. then it will fit all area of window.

      http://doc.qt.io/qt-5/layout.html

      S 1 Reply Last reply 14 Apr 2016, 05:24
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 13 Apr 2016, 21:43 last edited by
        #3

        Hi,

        Did you call QDockWidget::setWidget ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        S 1 Reply Last reply 14 Apr 2016, 05:17
        0
        • S SGaist
          13 Apr 2016, 21:43

          Hi,

          Did you call QDockWidget::setWidget ?

          S Offline
          S Offline
          saitej
          wrote on 14 Apr 2016, 05:17 last edited by
          #4

          @SGaist :
          Ya I have called that code ...

          1 Reply Last reply
          0
          • M mrjj
            13 Apr 2016, 14:07

            @saitej said:
            hi for a docked window, you would add a
            layout to it first and then insert the controls
            in that layout. then it will fit all area of window.

            http://doc.qt.io/qt-5/layout.html

            S Offline
            S Offline
            saitej
            wrote on 14 Apr 2016, 05:24 last edited by
            #5

            @mrjj
            Ya I have already used this code.

            QVBoxLayout *layout = new QVBoxLayout;
                layout->addWidget(ui->tableView);
            
                layout->addWidget(ui->addButton);
                layout->addWidget(ui->deleteButton);
            
                QWidget *widget = new QWidget;
                widget->setLayout(layout);
                    setCentralWidget(widget);
            

            But I am getting the following error.
            error: 'setCentralWidget' was not declared in this scope
            setCentralWidget(widget);
            ^

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 14 Apr 2016, 09:23 last edited by
              #6

              @saitej said:

              setCentralWidget

              This is only valid with a QMainwindow. :)

              You would do
              (the code u shown)
              and then
              DockWidget->setWidget (widget);

              S 1 Reply Last reply 14 Apr 2016, 09:49
              0
              • M mrjj
                14 Apr 2016, 09:23

                @saitej said:

                setCentralWidget

                This is only valid with a QMainwindow. :)

                You would do
                (the code u shown)
                and then
                DockWidget->setWidget (widget);

                S Offline
                S Offline
                saitej
                wrote on 14 Apr 2016, 09:49 last edited by
                #7

                @mrjj :

                I already tried dis code but of no use. It is giving the same output.

                   QVBoxLayout *layout = new QVBoxLayout;
                    layout->addWidget(ui->tableView);
                
                    layout->addWidget(ui->addButton);
                    layout->addWidget(ui->deleteButton);
                
                //    QWidget *widget = new QWidget;
                    QDockWidget *DockWidget = new QDockWidget;
                    DockWidget->setLayout(layout);
                    DockWidget->setWidget (DockWidget);
                
                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 14 Apr 2016, 09:59 last edited by
                  #8

                  Don't set the layout on DockWidget.

                  By the way, there's something fishy in your code. Did you create your widget with designer and now trying to use it with a QMainWindow ?

                  Because it looks like you are trying to create the dock widget from within your custom widget and not from a QMainWindow derived class.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply 14 Apr 2016, 10:15
                  0
                  • S SGaist
                    14 Apr 2016, 09:59

                    Don't set the layout on DockWidget.

                    By the way, there's something fishy in your code. Did you create your widget with designer and now trying to use it with a QMainWindow ?

                    Because it looks like you are trying to create the dock widget from within your custom widget and not from a QMainWindow derived class.

                    S Offline
                    S Offline
                    saitej
                    wrote on 14 Apr 2016, 10:15 last edited by
                    #9

                    @SGaist

                    First I have created the dock in the mainwindow and I am creating the table on the dock through a table class. This layout function is in the class.
                    Suggest me the right way of getting this done.
                    MainWindow Code:

                    // Dock Creation
                      this->setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
                        this->setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
                        this->setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
                        this->setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
                    // table creation
                    QDockWidget *dock = new QDockWidget("Way Point Table",this);
                        wayPointTable *wptable = new wayPointTable();
                        dock->setWidget(wptable);
                        dock->setFixedSize(500, 300);
                    
                        this->addDockWidget(Qt::BottomDockWidgetArea, dock);
                    

                    WayPointTable class has this code:

                    ui->tableView->verticalHeader()->setDefaultAlignment(Qt::AlignVCenter | Qt::AlignRight);
                        ui->tableView->horizontalHeader()->setStretchLastSection(true);
                        ui->tableView->resizeColumnsToContents();
                    
                    QVBoxLayout *layout = new QVBoxLayout;
                        layout->addWidget(ui->tableView);
                    
                        layout->addWidget(ui->addButton);
                        layout->addWidget(ui->deleteButton);
                    
                    //    QWidget *widget = new QWidget;
                        QDockWidget *DockWidget = new QDockWidget;
                        DockWidget->setLayout(layout);
                        DockWidget->setWidget (DockWidget);
                    //            setCentralWidget(widget);
                    
                       
                    
                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 14 Apr 2016, 10:19 last edited by
                      #10

                      There's no need for any dock widget related code in WayPointTable. Also DockWidget->setWidget (DockWidget); doesn't really make sense.

                      One thing to clean, since you used designer for that widget, why are you setting a layout in code ? You should put it directly in through designer.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      S 1 Reply Last reply 14 Apr 2016, 10:45
                      1
                      • S SGaist
                        14 Apr 2016, 10:19

                        There's no need for any dock widget related code in WayPointTable. Also DockWidget->setWidget (DockWidget); doesn't really make sense.

                        One thing to clean, since you used designer for that widget, why are you setting a layout in code ? You should put it directly in through designer.

                        S Offline
                        S Offline
                        saitej
                        wrote on 14 Apr 2016, 10:45 last edited by saitej
                        #11

                        @SGaist
                        How to set the tableview to occupy the entire dock window through the designer ? I have put the tableview and the 2 buttons in a formlayout.

                        1 Reply Last reply
                        0
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 14 Apr 2016, 11:15 last edited by
                          #12

                          Did you set the form layout properly on the widget in designer ?

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          S 1 Reply Last reply 14 Apr 2016, 11:17
                          0
                          • S SGaist
                            14 Apr 2016, 11:15

                            Did you set the form layout properly on the widget in designer ?

                            S Offline
                            S Offline
                            saitej
                            wrote on 14 Apr 2016, 11:17 last edited by
                            #13

                            @SGaist Ya

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 14 Apr 2016, 11:20 last edited by
                              #14

                              By the way, why a form layout ?

                              You should either have everything in a QVBoxLayout or if you want the buttons to be side by side, put them in a QHBoxLayout within the main QVBoxLayout.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              S 1 Reply Last reply 14 Apr 2016, 11:24
                              0
                              • S SGaist
                                14 Apr 2016, 11:20

                                By the way, why a form layout ?

                                You should either have everything in a QVBoxLayout or if you want the buttons to be side by side, put them in a QHBoxLayout within the main QVBoxLayout.

                                S Offline
                                S Offline
                                saitej
                                wrote on 14 Apr 2016, 11:24 last edited by saitej
                                #15

                                @SGaist
                                These layouts are not giving the required display. I have played with the different layouts. After putting the layout code along with the setcentralwidget, then it had worked when I had used on the mainwindow.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 14 Apr 2016, 11:25 last edited by
                                  #16

                                  So a table view on top of an add button on top of a delete button ? That's what QVBoxLayout is for.

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  S 1 Reply Last reply 14 Apr 2016, 11:30
                                  0
                                  • S SGaist
                                    14 Apr 2016, 11:25

                                    So a table view on top of an add button on top of a delete button ? That's what QVBoxLayout is for.

                                    S Offline
                                    S Offline
                                    saitej
                                    wrote on 14 Apr 2016, 11:30 last edited by
                                    #17

                                    @SGaist I want the display as in image 2. The table occupies the entire window. I am getting as shown in Image 1

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on 14 Apr 2016, 11:41 last edited by
                                      #18

                                      If you get what's on image1 it means that you didn't apply the QVBoxLayout properly. With it these buttons can't be side by side unless:

                                      1. They are in a QHBoxLayout
                                      2. Not in a layout at all but you put them side by side on the widget in designer.

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      S 1 Reply Last reply 14 Apr 2016, 11:48
                                      0
                                      • S SGaist
                                        14 Apr 2016, 11:41

                                        If you get what's on image1 it means that you didn't apply the QVBoxLayout properly. With it these buttons can't be side by side unless:

                                        1. They are in a QHBoxLayout
                                        2. Not in a layout at all but you put them side by side on the widget in designer.
                                        S Offline
                                        S Offline
                                        saitej
                                        wrote on 14 Apr 2016, 11:48 last edited by
                                        #19

                                        @SGaist
                                        The buttons are not the problem I want the tableview to occupy the entire dock but it is coming in a fixed size how much ever i increase the dock size.
                                        Image

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 14 Apr 2016, 11:50 last edited by
                                          #20

                                          hi
                                          Here is a sample that uses a UI and scale with the dock
                                          https://www.dropbox.com/s/6ipc9ap6hjvcpr9/ilovemydocks.zip?dl=0
                                          Maybe it can provide some hint.
                                          Note the UI is widget based for this to work.

                                          S 1 Reply Last reply 14 Apr 2016, 12:20
                                          0

                                          1/28

                                          13 Apr 2016, 13:45

                                          • Login

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