Quote Originally Posted by momesana View Post
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!

Qt Code:
  1. #include <QtGui>
  2. #include <QList>
  3.  
  4. int main(int argc, char** argv)
  5. {
  6. QApplication app(argc, argv);
  7.  
  8. QSplitter* splitter = new QSplitter(Qt::Vertical);
  9. for (int i = 0; i < 3; ++i) {
  10. QTextEdit* te = new QTextEdit("Text Edit nr. " + QString::number(i));
  11. splitter->addWidget(te);
  12. if (i % 2 == 0)
  13. te->resize(te->sizeHint().width(), te->fontMetrics().height() * 2);
  14. }
  15.  
  16. // Set the initial sizes for QSplitter widgets
  17. QList<int> sizes;
  18. sizes << 100 << 150 << 200;
  19. splitter->setSizes(sizes);
  20.  
  21. mw.setCentralWidget(splitter);
  22. mw.show();
  23. return app.exec();
  24. }
To copy to clipboard, switch view to plain text mode