QTableWidget row insertion and set width of each column?
Hi,
I placed a QTableWidget on a form and i created three columns in this table widget through QT Designer and now want to add rows in this table widget through coding.
My problems are:-
(1) How to add rows in this table widget through coding.
(2) How to set width of each column through QT Designer and through coding.
Thanks and regards
Re: QTableWidget row insertion and set width of each column?
Hi,
1) Try insertRow(),
2) If I'm not wrong you have to set the width of the horizontal header to have all the column to resize.
Simone
Re: QTableWidget row insertion and set width of each column?
Quote:
Originally Posted by
darpan
(1) How to add rows in this table widget through coding.
Something like this:
Code:
int row = tableWidget->rowCount(); // current row count
tableWidget->setRowCount(row+1); // add one row
// create items in all added cells
for (int col = 0; col < tableWidget->columnCount(); ++c)
{
tableWidget->setItem(row, col, newItem);
}
Quote:
Originally Posted by
darpan
(2) How to set width of each column through QT Designer and through coding.
to access headers:
to resize:
Re: QTableWidget row insertion and set width of each column?
Hi,
I read the following functions but can't get how to set width of each column in QTreeWidget through QT Designer and through coding.
to access headers:
QTableView::horizontalHeader()
QTableView::verticalHeader()
to resize:
QHeaderView::resizeSection()
QHeaderView::setStretchLastSection()
QHeaderView::setResizeMode()
...
Please give some code example to set the width of QTreeWidget Column.
Thanks and Regards
Re: QTableWidget row insertion and set width of each column?
I thought it was QTableWidget.. :)
Code:
#include <QHeaderView>
treeWidget->header()->resizeSection(0, 20); // column 0, width 20
tableWidget->horizontalHeader()->resizeSection(1, 50); // column 1, width 50
tableWidget->verticalHeader()->resizeSection(2, 15); // row 2, height 15
Re: QTableWidget row insertion and set width of each column?
Hi,
First of all sorry , you are right, it was QTableWidget. I had to set width of Each column of QTable Widget.
I also have requirement to delete all rows created through following lines:-
row = tableWidget->rowCount(); // current row count
tableWidget->setRowCount(row+1); // add one row
I am able to clear the whole QTableWidget but how i can delete all the rows created through setRowCount(row+1).
Thanks and Regards
Re: QTableWidget row insertion and set width of each column?
You can always use QTableView::setColumnWidth() and call this both when your widget class is initialized and/or after your data loads.
For removing the rows, tableWidget->removeRow(row+1) ??