Make QTableWidget expand when dialog window size is changed
-
I have a tablewidget, and a textEdit, and cancel +okay bottons
I want these widgets to stay in the relative position to each other, and the tablewidget to expand if the dialog window is expanded or size changed...how can i do that?
-
Use a layout manager, "gridlayout":http://doc.qt.nokia.com/latest/qgridlayout.html should work for you.
-
Please read the "introduction on layout management":http://doc.qt.nokia.com/latest/layout.html from the documentation.
For positioning the cancel and OK buttons, I would recommend you look into using a QDialogButtonBox. It will automatically layout and order the buttons for you in the way your platform prescribes.
-
so i have this
@QGridLayout *layout=new QGridLayout();
ui->tableWidget->setSizePolicy(QSizePolicy::Expanding);
layout->addWidget(ui->tableWidget,0,0,-1,-1,Qt::AlignVCenter);
layout->addWidget(ui->textEdit_2,1,0,1,2,Qt::AlignLeft);
layout->addWidget(ui->cancel,1,1);
layout->addWidget(ui->ok,1,2);
this->setLayout(layout); @but only a tiny box is created for viewing of each widget... the widget doesnt fill up the cell in the grid... and the setSizePolicy gave me error of it being private and cant be accessed.... ???
-
although the widgets, buttons do change position and size with respect to the parent dialog window