QTableWidget adjust column and row size
-
Hi! How can I adjust column width in QTableWidget as long as I resize the window, that holds QTableWidget? I need width of each coloumn and height of each row be resized when I resize the window, how can I achieve this?
-
You can set the headers resize mode to be "QHeaderView::Stretch":http://doc.qt.nokia.com/latest/qheaderview.html#ResizeMode-enum, then the columns and rows will resize when you resize the widget. Does doing so solve your problem?
For example:
@
#include <QtGui>
class TableWidget : public QTableWidget
{
Q_OBJECT
public:
TableWidget()
{
setRowCount(10);
setColumnCount(5);
QTableWidgetItem *newItem = new QTableWidgetItem("An item");
setItem(0,0, newItem);
horizontalHeader()->setResizeMode(QHeaderView::Stretch);
verticalHeader()->setResizeMode(QHeaderView::Stretch);
}
};#include "main.moc"
int main(int argc, char** argv)
{
QApplication app(argc, argv);
TableWidget window;
window.resize(400,400);
window.show();
return app.exec();}
@
-
sigrid,
Thanks for your reply!
It is working perfectly.