Results 1 to 4 of 4

Thread: initial size of widgets in a QSplitter

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: initial size of widgets in a QSplitter

    Quote Originally Posted by tsp View Post
    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 
    Needless to say, setSizes was the first thing I tried back then ;-). The stuff didn't work as you can see with this code:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv)
    4. {
    5. QApplication app(argc, argv);
    6.  
    7. QList<int> sizes;
    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. sizes << ((i % 2 == 0) ? te->fontMetrics().height() * 2 : te->sizeHint().height());
    13. }
    14. // Set the initial sizes for QSplitter widgets
    15. splitter->setSizes(sizes);
    16.  
    17. mw.setCentralWidget(splitter);
    18. mw.show();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    Does anyone have any ideas?

    Thanx in advance

    P.s. @tsp: The QtGui module includes QtCore which in turns includes QtList. Thus there is no need for that headerfile to be included in the example you provided.

  2. #2
    Join Date
    Aug 2010
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: initial size of widgets in a QSplitter

    Did you solve it? If yes, please post a small example.

    Regards.

Similar Threads

  1. Replies: 4
    Last Post: 11th July 2010, 09:47
  2. Adjust the initial size of a QTextEdit in a layout
    By hecinho in forum Qt Programming
    Replies: 0
    Last Post: 26th November 2009, 15:58
  3. resizing widgets depending on a main widget size
    By luf in forum Qt Programming
    Replies: 6
    Last Post: 10th October 2009, 16:13
  4. Size proportions of widgets in QSplitter
    By Boron in forum Qt Programming
    Replies: 2
    Last Post: 9th October 2009, 18:25
  5. Replies: 1
    Last Post: 27th March 2008, 15:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.