PDA

View Full Version : Is there a way to find when resize is done??



rajji_saini
6th September 2012, 01:14
Hi,

Is there any signal or a way to check when resize is complete for QWidget?
Actually I want to stop the drawing on my map control when it is being resized and then start it again once the resize is complete.

Regards,
Raj

viulskiez
6th September 2012, 10:42
Is there any signal or a way to check when resize is complete for QWidget?
Try reimplement QWidget::resizeEvent or using QObject::eventFilter.

ChrisW67
7th September 2012, 07:45
When do you consider the resize "complete"?

You can do something like this, which stops the widget's layout from updating until there has been no resize event for a configurable time:


#include <QtGui>
#include <QDebug>

class LazyResizeWidget: public QWidget
{
Q_OBJECT
public:
LazyResizeWidget(QWidget *p = 0): QWidget(p)
{
m_timer = new QTimer(this);
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), SLOT(resizeStopped()));

// Just for example content
QFrame *f = new QFrame(this);
f->setFrameStyle(QFrame::Plain | QFrame::Box);
QVBoxLayout *l = new QVBoxLayout(this);
l->addWidget(f);
setLayout(l);
}

protected:
void resizeEvent(QResizeEvent *event)
{
QLayout *l = layout();
if (l) {
m_timer->start(StoppedTimeout);
l->setEnabled(false);
}
QWidget::resizeEvent(event);
}

private slots:
void resizeStopped()
{
QLayout *l = layout();
if (l) {
l->setEnabled(true);
l->update();
}
}

private:
enum { StoppedTimeout = 500 };
QTimer *m_timer;
};


int main(int argc, char**argv)
{
QApplication app(argc, argv);
LazyResizeWidget w;
w.resize(640, 480);
w.show();
return app.exec();
}

#include "main.moc"

Coises
8th September 2012, 23:16
Is there any signal or a way to check when resize is complete for QWidget?
Actually I want to stop the drawing on my map control when it is being resized and then start it again once the resize is complete.

Do you mean when the user is resizing the window (by dragging an edge or a corner)?

If so, and if the target platform is Windows, what you need are the WM_ENTERSIZEMOVE (http://msdn.microsoft.com/en-us/library/ms632622(v=vs.85)) and WM_EXITSIZEMOVE (http://msdn.microsoft.com/en-us/library/ms632623(v=vs.85)) messages. I don’t have a good opportunity to test right now, but if QWidget::winEvent gets those messages, you should be able to use them to do what you need.

rajji_saini
9th October 2013, 19:18
Thanks Coises ...