I have a QT GUI application, it has a vertical layout all the controls expand to fill the layout. If I add a QTextBox to the layout it has a fixed size (too big), I can change this in the designer or in code (in the MainWindow constructor)
m_textEdit->setMaximumHeight(3 * RowHeight);
but then it seems it is fixed permanently. I want to make it bigger when it has focus.
I have tried css
m_textEdit->setStyleSheet("QPlainTextEdit:focus{max-height: 400px}");
I have tried the resize function which is called in an action
m_textEdit->resize(m_textEdit->width(), 3 * RowHeight);
also doesn't resize once displayed.
I also thought that maybe I could put it in a splitter layout which would then be resizeable, but then the controls didn't expand with the window size.
Any ideas anyone?
The way I did this in the end is to add a QLabel and a QTextEdit to the form, then I right click on form and layout->'break layout' (why, I don't know!), then I select both widgets and add them to a vertical splitter layout (by right clicking form and layout->'vertical splitter'). Then I right click on form and add a vertical layout which then sets the all important layout to the MainWidget and lets the controls scale with the window size (the red warning icon disappears from the mainwidget). To get the vertical proportions I want at startup I have to also add the following code
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QList<int> sizes;
sizes << 1000 << 1;
ui->splitter->setStretchFactor(0,1000);
ui->splitter->setStretchFactor(1,1);
}
I also have to set the size policy to expanding on the widgets (not sure this is required)