Hi,
recently someone on freenode asked how to set the initial height of three Text Edits inside a QSplitter with a vertical orientation. I tried to help him but failed miserably . It was possible to set the height if you used setMaximumHeight but he wanted the size to be adjustable by the user (otherwise using a QSplitter wouldn't have made sense anyway) which isa legitimate and reasonable request after all. The top and the bottom text edits shall take up twice the height of the current font. The text edit in between should get the rest.
I tried this and it didn't work
#include <QtGui>
int main(int argc, char** argv)
{
for (int i = 0; i < 3; ++i) {
splitter->addWidget(te);
if (i % 2 == 0)
te->resize(te->sizeHint().width(), te->fontMetrics().height() * 2);
}
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
#include <QtGui>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QSplitter* splitter = new QSplitter(Qt::Vertical);
for (int i = 0; i < 3; ++i) {
QTextEdit* te = new QTextEdit("Text Edit nr. " + QString::number(i));
splitter->addWidget(te);
if (i % 2 == 0)
te->resize(te->sizeHint().width(), te->fontMetrics().height() * 2);
}
QMainWindow mw;
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Any Ideas?
Thanks in advance
Bookmarks