Results 1 to 7 of 7

Thread: How to resize a QDockWidget when startup the program?

  1. #1

    Default How to resize a QDockWidget when startup the program?

    My program just looks like qt's designer which has a central widget in the middle and dock widgets on two sides.

    The problem is that when i start the program, the central widget filled almost all client area and the width of dock widgets on two sides are really small.

    I tried resize(), but it seems not work.

    Any thoughts would be great, Thanks.

    Last edited by heavenstar_x; 29th April 2007 at 22:57.

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resize a QDockWidget when startup the program?

    Use setMinimumSize in the dock widgets.

    Regards

  3. #3

    Default Re: How to resize a QDockWidget when startup the program?

    thanks, it works.

  4. #4
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to resize a QDockWidget when startup the program?

    Why setMinimumSize does not work for me??!!

    Here is code:
    Qt Code:
    1. void qKobilica::addShortcutWidget(QToolBox* pToolBox)
    2. {
    3. m_pMenuShortcutWidget=new QDockWidget(trUtf8("Hitri meni"), this);
    4. Q_CHECK_PTR(m_pMenuShortcutWidget); // checks widget creation
    5.  
    6. /*
    7.   m_pMenuShortcutWidgetSA=new QScrollArea(m_pMenuShortcutWidget);
    8.   Q_CHECK_PTR(m_pMenuShortcutWidgetSA); // checks scroll area creation
    9.  
    10.   m_pMenuShortcutWidgetSA->setBackgroundRole(QPalette::Dark);
    11.   m_pMenuShortcutWidgetSA->setWidget(m_pMenuShortcutWidget);
    12.   m_pMenuShortcutWidgetSA->setMinimumSize(0, 0);
    13.   m_pMenuShortcutWidgetSA->setMaximumSize(1500, 1000);
    14.   m_pMenuShortcutWidgetSA->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
    15.   m_pMenuShortcutWidgetSA->ensureWidgetVisible(m_pMenuShortcutWidget);
    16. */
    17.  
    18. m_pMenuShortcutWidget->setMinimumSize(200, 600);
    19. //m_pMenuShortcutWidget->setMaximumSize(1500, 100);
    20. m_pMenuShortcutWidget->setFeatures(QDockWidget::NoDockWidgetFeatures |
    21. QDockWidget::DockWidgetClosable |
    22. QDockWidget::DockWidgetMovable |
    23. QDockWidget::DockWidgetFloatable);
    24. m_pMenuShortcutWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); // sets allowed docked area
    25. //m_pMenuShortcutWidget->setWidget(m_pMenuShortcutWidgetSA);
    26. m_pMenuShortcutWidget->setWidget(pToolBox);
    27. addDockWidget(Qt::LeftDockWidgetArea, m_pMenuShortcutWidget); // places widget
    28. }
    To copy to clipboard, switch view to plain text mode 
    Qt 5.3 Opensource & Creator 3.1.2

  5. #5
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to resize a QDockWidget when startup the program?

    Hi, I suggest to consider using QMainWindow saveState/restoreState - you're adding just view lines of code and application opens with sizes it had when you closed it in previous session... It's easy & comfortable i think...

  6. #6
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to resize a QDockWidget when startup the program?

    Ok, I got it, but i still want to know, is there any method that resizes QDockWidget when called, not just at startupe?!
    Qt 5.3 Opensource & Creator 3.1.2

  7. #7
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to resize a QDockWidget when startup the program?

    Try setMinimumSize of QDockWidgets (to some value that makes them wide enought, i.e. 25% of window's width) and make sure that minimumSize of central widget isn't to big to
    have enought place on widdow area for all widgets...

    You may also experiment with stretchFactors (in QSizePolicy) or with sizePolicies by itself.

Similar Threads

  1. Replies: 8
    Last Post: 4th February 2007, 00:42
  2. QT MySQL
    By sabeeshcs in forum Newbie
    Replies: 6
    Last Post: 12th January 2007, 04:19
  3. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32
  4. How to get a QDockWidget to auto resize?
    By bitChanger in forum Qt Programming
    Replies: 4
    Last Post: 6th January 2006, 16: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.