PDA

View Full Version : How to resize a QDockWidget when startup the program?



heavenstar_x
29th April 2007, 23:53
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.

:confused:

marcel
30th April 2007, 04:16
Use setMinimumSize in the dock widgets.

Regards

heavenstar_x
30th April 2007, 12:33
thanks, it works.

MarkoSan
26th October 2007, 05:02
Why setMinimumSize does not work for me??!! :confused::confused::confused::confused:

Here is code:

void qKobilica::addShortcutWidget(QToolBox* pToolBox)
{
m_pMenuShortcutWidget=new QDockWidget(trUtf8("Hitri meni"), this);
Q_CHECK_PTR(m_pMenuShortcutWidget); // checks widget creation

/*
m_pMenuShortcutWidgetSA=new QScrollArea(m_pMenuShortcutWidget);
Q_CHECK_PTR(m_pMenuShortcutWidgetSA); // checks scroll area creation

m_pMenuShortcutWidgetSA->setBackgroundRole(QPalette::Dark);
m_pMenuShortcutWidgetSA->setWidget(m_pMenuShortcutWidget);
m_pMenuShortcutWidgetSA->setMinimumSize(0, 0);
m_pMenuShortcutWidgetSA->setMaximumSize(1500, 1000);
m_pMenuShortcutWidgetSA->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
m_pMenuShortcutWidgetSA->ensureWidgetVisible(m_pMenuShortcutWidget);
*/

m_pMenuShortcutWidget->setMinimumSize(200, 600);
//m_pMenuShortcutWidget->setMaximumSize(1500, 100);
m_pMenuShortcutWidget->setFeatures(QDockWidget::NoDockWidgetFeatures |
QDockWidget::DockWidgetClosable |
QDockWidget::DockWidgetMovable |
QDockWidget::DockWidgetFloatable);
m_pMenuShortcutWidget->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); // sets allowed docked area
//m_pMenuShortcutWidget->setWidget(m_pMenuShortcutWidgetSA);
m_pMenuShortcutWidget->setWidget(pToolBox);
addDockWidget(Qt::LeftDockWidgetArea, m_pMenuShortcutWidget); // places widget
}

mchara
26th October 2007, 12:40
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...

MarkoSan
26th October 2007, 13:41
Ok, I got it, but i still want to know, is there any method that resizes QDockWidget when called, not just at startupe?!

mchara
26th October 2007, 13:58
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.