Results 1 to 12 of 12

Thread: How to change QMainWindow size at runtime?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Jan 2011
    Posts
    19
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to change QMainWindow size at runtime?

    I've found the root cause

    Qt Code:
    1. QSize QWidgetPrivate::adjustedSize() const
    2. {
    3. Q_Q(const QWidget);
    4.  
    5. QSize s = q->sizeHint();
    6.  
    7. if (q->isWindow()) {
    8. Qt::Orientations exp;
    9. if (layout) {
    10. if (layout->hasHeightForWidth())
    11. s.setHeight(layout->totalHeightForWidth(s.width()));
    12. exp = layout->expandingDirections();
    13. } else
    14. {
    15. if (q->sizePolicy().hasHeightForWidth())
    16. s.setHeight(q->heightForWidth(s.width()));
    17. exp = q->sizePolicy().expandingDirections();
    18. }
    19. if (exp & Qt::Horizontal)
    20. s.setWidth(qMax(s.width(), 200));
    21. if (exp & Qt::Vertical)
    22. s.setHeight(qMax(s.height(), 100));
    23. #if defined(Q_WS_X11)
    24. QRect screen = QApplication::desktop()->screenGeometry(q->x11Info().screen());
    25. #else // all others
    26. QRect screen = QApplication::desktop()->screenGeometry(q->pos());
    27. #endif
    28. #if defined (Q_WS_WINCE) || defined (Q_OS_SYMBIAN)
    29. s.setWidth(qMin(s.width(), screen.width()));
    30. s.setHeight(qMin(s.height(), screen.height()));
    31. #else
    32. s.setWidth(qMin(s.width(), screen.width()*2/3));
    33. s.setHeight(qMin(s.height(), screen.height()*2/3));
    34. #endif
    35. if (QTLWExtra *extra = maybeTopData())
    36. extra->sizeAdjusted = true;
    37. }
    38.  
    39. if (!s.isValid()) {
    40. QRect r = q->childrenRect(); // get children rectangle
    41. if (r.isNull())
    42. return s;
    43. s = r.size() + QSize(2 * r.x(), 2 * r.y());
    44. }
    45.  
    46. return s;
    47. }
    To copy to clipboard, switch view to plain text mode 

    The root was that window has a default size policy, so adjustSize() never ran into using childrenRect to expand size. How could I avoid to it?


    Added after 4 minutes:


    Quote Originally Posted by Lykurg View Post
    You have to resize() your mainwindow, not the frame inside it. And calling adjustSize() destroy all other setting you made before.
    but I can't get the total size of frame plus other bars (toolbar, menubar, etc).
    Last edited by myfifth; 7th January 2011 at 09:22.

Similar Threads

  1. QToolbar - change icon at runtime ?
    By pl01 in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2010, 17:51
  2. Change QPixmap image at runtime
    By Qt Coder in forum Qt Programming
    Replies: 12
    Last Post: 30th March 2009, 12:37
  3. Replies: 2
    Last Post: 23rd March 2009, 17:26
  4. how change language at runtime?
    By mattia in forum Newbie
    Replies: 3
    Last Post: 14th November 2007, 18:36
  5. change font size and button size of QMessageBox
    By nass in forum Qt Programming
    Replies: 6
    Last Post: 13th September 2006, 19:16

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.