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. Nice2See: QTablewidget fit in Widget
Forum Updated to NodeBB v4.3 + New Features

Nice2See: QTablewidget fit in Widget

Scheduled Pinned Locked Moved General and Desktop
16 Posts 6 Posters 7.6k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    huckfinn
    wrote on last edited by
    #1

    Hello,

    as you can see in the pic, I have a Table which does not look nice. The last column is cut.
    !http://img688.imageshack.us/img688/4107/screenqte.png(Screen)!

    There must be a property, where I can bind the QTableWidget to its parent, such that when I load a table the optimal width is loaded. The heigth might be fixed, set by myself.
    And when I resize the mainWindow the table should be adopted to that..

    I hope I could explain that..

    Cheers Huck

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dangelog
      wrote on last edited by
      #2

      It seems to me that the tab Measure has a QWidget inside, and your QTableWidget is inside that widget, and that no layout is installed. Am I correct?

      (Solutions: either put the QTableWidget directly inside the tab, or install a layout).

      Software Engineer
      KDAB (UK) Ltd., a KDAB Group company

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #3

        I agree with previous poster... Also, I might add, you could find that the last column(s) remains cut: if that's the case, you could either use a smaller font or manually set each column's width to a suitable size (was it setSizeHint?)

        --

        1 Reply Last reply
        0
        • L Offline
          L Offline
          ludde
          wrote on last edited by
          #4

          Are you adding the table widget to the tab widget directly, using addTab()? In that case I would expect it to use all the space available inside the tab page. But maybe you are doing something more complicated?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Bottom line: please show the code that creates this dialog.

            Nice looking style, by the way!

            1 Reply Last reply
            0
            • H Offline
              H Offline
              huckfinn
              wrote on last edited by
              #6

              [quote author="peppe" date="1314053648"]It seems to me that the tab Measure has a QWidget inside, and your QTableWidget is inside that widget, and that no layout is installed. Am I correct?[/quote]
              Isn't a Layout already installed? Or do you mean another Layout on a upper level?
              @
              void MainWindow::createVizual()
              {
              initMainWidget = new QWidget;
              initWidTab = new QWidget;
              QWidget *testTab = new QWidget;

              dTabWidget = new QTabWidget;
              dTabWidget->addTab(initWidTab, tr("Measure"));
              dTabWidget->addTab(testTab, tr("Test"));
              
              QPushButton *button = new QPushButton("My button");
              mainLayout = new QVBoxLayout;
              mainLayout->addWidget(dTabWidget);
              mainLayout->addWidget(button);
              initMainWidget->setLayout(mainLayout);
              
              setCentralWidget(initMainWidget);
              

              }
              @

              [quote]
              was it setSizeHint?
              [/quote]
              No, I have used:
              @
              dTableWidget->setGeometry(5, 25, TABLEWIDTH+5, initWidTab->height()-5);
              @

              [quote]
              Are you adding the table widget to the tab widget directly, using addTab()?
              [/quote]

              Yes, as you can see above, both Tabs were added by addTab().

              [quote]
              Bottom line: please show the code that creates this dialog.
              Nice looking style, by the way!
              [/quote]
              Code is above this post. Styles were the standard settings in Qt. I haven't changed any configuration there ;)

              1 Reply Last reply
              0
              • H Offline
                H Offline
                huckfinn
                wrote on last edited by
                #7

                As far as i understood you, the Layout should be insallet here in between?

                @
                void MainWindow::createTable()
                {
                QStringList dHeaderLabels;
                dHeaderLabels << "Date" << "1" << "2" << "3" << "4" << "5" << "6" << "7" << "8" << "#Subjects" << "#Sum";

                /* Table settings and fonts */
                dTableWidget = new QTableWidget(0, COLUMCOUNT, initWidTab);
                dTableWidget->setGeometry(5, 25, TABLEWIDTH+5, initWidTab->height()-5);
                dTableWidget->setColumnWidth(0, this->TABLEDATEWIDTH);
                dTableWidget->setColumnWidth(1, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(2, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(3, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(4, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(5, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(6, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(7, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(8, this->TABLENUMBERWIDTH);
                dTableWidget->setColumnWidth(9, TABLENUMBERWIDTH*20);
                dTableWidget->setColumnWidth(10, TABLENUMBERWIDTH*20);
                dTableWidget->setHorizontalHeaderLabels(dHeaderLabels);
                dTableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
                

                // dTableWidget->addScrollBarWidget(initWidTab, Qt::AlignRight);
                }
                @

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  So... where do you create that table (where do you call createTable)? And where do you add that table to a layout?

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mrtc3
                    wrote on last edited by
                    #9

                    Layout should be between initWidTab and dTableWidget I guess?

                    There are 10 types. Those who understand binary and those who don't .)

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      huckfinn
                      wrote on last edited by
                      #10

                      [quote author="Andre" date="1314443881"]So... where do you create that table (where do you call createTable)? And where do you add that table to a layout?[/quote]

                      The createTable is created in the Constructor:
                      @
                      MainWindow::MainWindow(QWidget *parent)
                      : QMainWindow(parent)
                      {
                      init();
                      }

                      void MainWindow::init()
                      {
                      createActions();
                      createMenus();
                      createStatusBar();
                      createVizual();
                      createTable();
                      setWindowTitle( tr("%1 v%2.%4").arg(APPNAME).arg(MAJOR_VERSION).arg(MINOR_VERSION) );
                      }
                      @

                      And the is not added to a Layout. I just set the parent as initWidTab as in the code above.

                      1 Reply Last reply
                      0
                      • O Offline
                        O Offline
                        octal
                        wrote on last edited by
                        #11

                        I think the best solution would be to add your Table to a layout.

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          huckfinn
                          wrote on last edited by
                          #12

                          Instead of a Widget.. I'll try that at home asap. Thanks.

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #13

                            Basically:
                            Except for the top level widget, every widget needs to be in a layout, and every layout needs to be either in another layout or set as the layout for a widget.

                            If one item disconnected from this tree, then the layouting will not work properly.

                            1 Reply Last reply
                            0
                            • H Offline
                              H Offline
                              huckfinn
                              wrote on last edited by
                              #14

                              Hello,

                              this is my architecture:
                              mainLayout
                              +--> dTabWidget (TabWidget)
                              +--> initWidTab (Tab Item)
                              +--> dTableWidget (TableWidget)

                              I was trying putting a layout in betweeen initWidTab and dTableWidget:
                              @
                              QVBoxLayout importTabLO = new QVBoxLayout;
                              importTabLO.addWidget(initWidTab);
                              dTableWidget = new QTableWidget(0, COLUMCOUNT, importTabLO);
                              @

                              /mainwindow.cpp:65: error: no matching function for call to 'QTableWidget::QTableWidget(int, const quint32&, QVBoxLayout&)'

                              importTabLO is a Layout and thus not accepted - a widget is required as I understood?

                              I guess, casting would not solve this.

                              Anybody any suggestions?

                              Cheers Huck

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                andre
                                wrote on last edited by
                                #15

                                You are doing it the wrong way around. Currently, you are trying to put the tab widget in the layout. Instead, put the table widget in the layout, and set the layout as the layout on the tab widget:

                                @
                                QVBoxLayout importTabLayout = new QVBoxLayout;
                                dTableWidget = new QTableWidget(0, COLUMNCOUNT);
                                importTabLayout->addWidget(dTableWidget);
                                initWidTab->setLayout(importTabLayout);
                                @
                                Note that then putting widgets in layouts, they will be reparented automatically, so there is not even a need to set a parent explicitly for the table widget.

                                1 Reply Last reply
                                0
                                • H Offline
                                  H Offline
                                  huckfinn
                                  wrote on last edited by
                                  #16

                                  That works fine. Thank you Andre!

                                  I have a small question regarding the Mainwindow's width.
                                  I would like to adopt the mainwindows width to that table, depending on the numbers size' stored in my tables columns.
                                  For instance when I have big numbers in each col, my table might be real wide. So I would like to adopt my mainwindow, such that I dont need any Horizontal scrollbar..

                                  Thank you in advise.
                                  Cheers Huck

                                  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