PDA

View Full Version : Dock Widget Custom Resizing?



qtoptus
31st March 2014, 01:24
Is it possible to make the resizing of a QDockWidget happen after mouse release? Same as opaque sizing of the QSplitter?

Thanks.

qtoptus
2nd April 2014, 21:47
Is there a style-sheet attribute I need to set?

ChrisW67
2nd April 2014, 23:35
QSplitter uses the opaque resize flag to alter its behaviour to use a rubber band and not propagate resizes to the child widgets until the mouse is released.
As far as I can tell when the QDockwidget is floating resizing is handled by the window manager and not within Qt control.
When the QDockWidget is docked its resize behaviour would be controlled by QMainWindow layout and any splitters it may use.

If the content of the dock widget is expensive to redraw then you may be able to fake it by suppressing updates until some short time after the last resize event.


#include <QtGui>

class Widget: public QWidget {
Q_OBJECT
public:
Widget(QWidget *p = 0): QWidget(p) {
m_resizeTimer = new QTimer(this);
m_resizeTimer->setSingleShot(true);
m_resizeTimer->setInterval(250); // how many milliseconds after last resize event do we draw
connect(m_resizeTimer, SIGNAL(timeout()), SLOT(releaseResize()));
setStyleSheet(" Widget { background-color: blue; } ");
}
protected:
void resizeEvent(QResizeEvent * event) {
m_resizeTimer->start(); // start idle timer or restart running timer
setUpdatesEnabled(false);
QWidget::resizeEvent(event); // in case it is doing things that still need to happen
}

private slots:
void releaseResize() {
setUpdatesEnabled(true);
}

private:
QTimer *m_resizeTimer;
};

int main(int argc, char **argv){
QApplication app(argc, argv);
Widget w;
w.resize(320, 240);
w.show();
return app.exec();
}
#include "main.moc"


Or you could set a flag on the first resizeEvent(). Your paintEvent() should check the flag and draw something cheap if it is set, i.e. during resize. When the timer goes off reset the flag and call update() to redraw using the expensive version of paintEvent().