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:
{
m_timer->setSingleShot(true);
connect(m_timer, SIGNAL(timeout()), SLOT(resizeStopped()));
// Just for example content
l->addWidget(f);
setLayout(l);
}
protected:
{
if (l) {
m_timer->start(StoppedTimeout);
l->setEnabled(false);
}
}
private slots:
void resizeStopped()
{
if (l) {
l->setEnabled(true);
l->update();
}
}
private:
enum { StoppedTimeout = 500 };
};
int main(int argc, char**argv)
{
LazyResizeWidget w;
w.resize(640, 480);
w.show();
return app.exec();
}
#include "main.moc"
#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"
To copy to clipboard, switch view to plain text mode
Bookmarks