Solved finding similar functions of QTableWidget as that of QTableView
-
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?
Thanks
-
@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)
andfirst_table->setRowHeight(1,0)
? There are alsosetColumn
/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.
-
Hi,
Do you mean you want to see only your top left QTableWidget ?
-
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.
-
@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)
andfirst_table->setRowHeight(1,0)
? There are alsosetColumn
/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.
-
@JonB
With some experimentation, I got the desired result.