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. finding similar functions of QTableWidget as that of QTableView
Forum Updated to NodeBB v4.3 + New Features

finding similar functions of QTableWidget as that of QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 450 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.
  • Swati777999S Offline
    Swati777999S Offline
    Swati777999
    wrote on last edited by
    #1

    Hi All,

    I am trying to draw a table inside a widget. See the code below

    QWidget *myWidget = new QWidget();
    QGridLayout *tableLayout = new QGridLayout();
    
    QTableWidget *first_table=new QTableWidget();
    tableLayout->addWidget(first_table,0,0);
    first_table->setRowCount(7);
    first_table->setColumnCount(2);
    first_table->setColumnCount(2);
    first_table->setColumnWidth(0,100);
    
    QTableWidget *second_table=new QTableWidget();
    tableLayout->addWidget(second_table,2,0);
    
    QTableWidget *third_table=new QTableWidget();
    tableLayout->addWidget(third_table,0,2);
    
    QTableWidget *fourth_table=new QTableWidget();
    tableLayout->addWidget(fourth_table,2,2);
    
    myWidget->setLayout(tableLayout);
    QMainWindow::setCentralWidget(myWidget);
    

    I want to resize the outer widget at (0,0) to the size of the inner table. How is it possible to implement?

    ResizingTable_in_Widgets.PNG

    Thanks

    “ In order to be irreplaceable, one must always be different” – Coco Chanel

    1 Reply Last reply
    0
    • Swati777999S Swati777999

      @SGaist

      Whatever I've drawn for the table1 (top left one; first table) , I want to resize the inner table (QTableWidget first_table) according to the dimension of the outer table(QGridLayout tableLayout) i.e the inner table(QTableWidget first_table( shoudl coincide over the outer table(QGridLayout tableLayout).

      Then I will use a loop to implement same logic for other tables in the above picture.

      Hope I made my points more clearly.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @Swati777999
      I'm still not sure I quite understand. You have a layout (try not to call this a "table" as well, it's too confusing) containing 4 table widgets. As long as you show the other 3 table widgets I think it's going to be tricky to make the top-left one occupy the whole of the layout/outer table widget, as the other 3 and the cells they are in will take up some space.

      Since you have first_table->setColumnWidth(0,100) did you try, say, first_table->setColumnWidth(1,0) and first_table->setRowHeight(1,0)? There are also setColumn/RowHidden() methods to consider?

      As ever, trying out playing with settings in Qt Designer --- even if you're not going to use this in your final code --- may help.

      Swati777999S 1 Reply Last reply
      3
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Do you mean you want to see only your top left QTableWidget ?

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

        Swati777999S 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Do you mean you want to see only your top left QTableWidget ?

          Swati777999S Offline
          Swati777999S Offline
          Swati777999
          wrote on last edited by
          #3

          @SGaist

          Whatever I've drawn for the table1 (top left one; first table) , I want to resize the inner table (QTableWidget first_table) according to the dimension of the outer table(QGridLayout tableLayout) i.e the inner table(QTableWidget first_table( shoudl coincide over the outer table(QGridLayout tableLayout).

          Then I will use a loop to implement same logic for other tables in the above picture.

          Hope I made my points more clearly.

          “ In order to be irreplaceable, one must always be different” – Coco Chanel

          JonBJ 1 Reply Last reply
          0
          • Swati777999S Swati777999

            @SGaist

            Whatever I've drawn for the table1 (top left one; first table) , I want to resize the inner table (QTableWidget first_table) according to the dimension of the outer table(QGridLayout tableLayout) i.e the inner table(QTableWidget first_table( shoudl coincide over the outer table(QGridLayout tableLayout).

            Then I will use a loop to implement same logic for other tables in the above picture.

            Hope I made my points more clearly.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @Swati777999
            I'm still not sure I quite understand. You have a layout (try not to call this a "table" as well, it's too confusing) containing 4 table widgets. As long as you show the other 3 table widgets I think it's going to be tricky to make the top-left one occupy the whole of the layout/outer table widget, as the other 3 and the cells they are in will take up some space.

            Since you have first_table->setColumnWidth(0,100) did you try, say, first_table->setColumnWidth(1,0) and first_table->setRowHeight(1,0)? There are also setColumn/RowHidden() methods to consider?

            As ever, trying out playing with settings in Qt Designer --- even if you're not going to use this in your final code --- may help.

            Swati777999S 1 Reply Last reply
            3
            • JonBJ JonB

              @Swati777999
              I'm still not sure I quite understand. You have a layout (try not to call this a "table" as well, it's too confusing) containing 4 table widgets. As long as you show the other 3 table widgets I think it's going to be tricky to make the top-left one occupy the whole of the layout/outer table widget, as the other 3 and the cells they are in will take up some space.

              Since you have first_table->setColumnWidth(0,100) did you try, say, first_table->setColumnWidth(1,0) and first_table->setRowHeight(1,0)? There are also setColumn/RowHidden() methods to consider?

              As ever, trying out playing with settings in Qt Designer --- even if you're not going to use this in your final code --- may help.

              Swati777999S Offline
              Swati777999S Offline
              Swati777999
              wrote on last edited by
              #5

              @JonB
              With some experimentation, I got the desired result.

              “ In order to be irreplaceable, one must always be different” – Coco Chanel

              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