Originally Posted by
momesana
how to set the initial height of three Text Edits inside a QSplitter with a vertical orientation.
QSplitter::setSizes is a way to affect to initial sizes of each widget in the QSplitter. Next is a modified version of your code where the initial sizes are 100, 150 and 200 pixels.
If QSplitter::setSizes fails then you might want to check what are the original sizes of each widget by using QSplitter::sizes and if the original sizes are 0 then you are setting sizes too early in the construction phase!
#include <QtGui>
#include <QList>
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);
}
// Set the initial sizes for QSplitter widgets
QList<int> sizes;
sizes << 100 << 150 << 200;
splitter->setSizes(sizes);
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
#include <QtGui>
#include <QList>
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);
}
// Set the initial sizes for QSplitter widgets
QList<int> sizes;
sizes << 100 << 150 << 200;
splitter->setSizes(sizes);
QMainWindow mw;
mw.setCentralWidget(splitter);
mw.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks