You might want to rewrite the resizeEvent
function of the QDockWidget
widget. For that you need to subclass QDockWidget
.
class MYDockwidget : public QDockWidget
{
Q_OBJECT
public:
MYDockwidget(QWidget *parent = 0):
QDockWidget(parent)
{}
protected:
void resizeEvent(QResizeEvent *event)
{
QDockWidget::resizeEvent(event);
// Calulate Main window size here.
// the main window is accesible
// through the parent property.
}
};
This approach works, but binds the QDockWidget
's resizeEvent to the QMainWindow
. The proper solution is to emit a signal when the size of the QDockWidget
change.
For that you will need to define a custom signal and of course you want that signal with information about the event in question, hence our signal will be emited with a QSize
argument.
class MYDockwidget : public QDockWidget
{
Q_OBJECT
public:
MYDockwidget(QWidget *parent = 0):
QDockWidget(parent)
{}
signals:
void sizeChanged(QSize);
protected:
void resizeEvent(QResizeEvent *event)
{
QDockWidget::resizeEvent(event);
emit sizeChanged(event->size());
}
};
After that you can write code like:
// Inside your main window.
public slots:
void on_dock_size_changed(QSize)
MYDockwidget *dock = new MYDockwidget(this);
connect(dock, SIGNAL(sizeChanged(QSize)), this, SLOT(on_dock_size_changed(QSize)));
void on_dock_size_changed(QSize size)
{
// resize your main window here.
}
Disadvantage:
You will need to set the QDockWidget
's properties by hand (programmatically) unless you manage your self to insert your custom widget as a QTDesigner plugin.