Qt-interest Archive, August 2007
Flickering and Shaking
Message 1 in thread
Hi,
I am having trouble with the implementation of a dialog that I am
making, and I was hoping some of you could enlighten me in on what is
going on. Thanks in advance.
My application has a dialog that is visible on the screen, periodically
some widgets are added to it. Each time new widgets are added the
contents of the dialog does a little shaking and a flickering.
The attached files contains a class that shows what I am describing.
I will appreciate very much any tip you can offer me to investigate this
thing further. Thanks again.
Regards
Hernán Tylim
#ifndef _FLICKTEST_H__
#define _FLICKTEST_H__
#pragma once
#include <QtGui>
class FlickTest : public QWidget
{
Q_OBJECT
public:
FlickTest();
public slots:
void addWidgets();
private:
QWidget* container;
};
#endif
TEMPLATE = app
TARGET = FlickTest
DESTDIR = .
CONFIG += debug
INCLUDEPATH += .
DEPENDPATH += .
MOC_DIR += .
OBJECTS_DIR += debug
UI_DIR += ./ui
RCC_DIR += ./rcc
HEADERS += ./flicktest.h
SOURCES += ./main.cpp ./flicktest.cpp
#include <QtGui/QApplication>
#include <QtGui/QApplication>
#include <QtGui>
#include "flicktest.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
FlickTest test;
test.show();
a.connect(&a, SIGNAL(lastWindowClosed()), &a, SLOT(quit()));
return a.exec();
}
#include "flicktest.h"
#include "flicktest.h"
#include <QtGui>
FlickTest::FlickTest()
{
QPushButton* startButton;
startButton = new QPushButton;
startButton->setText("start");
connect( startButton , SIGNAL(clicked()) , SLOT(addWidgets()) );
container = new QWidget;
container->setLayout( new QVBoxLayout );
QWidget* inner = new QWidget;
inner->setLayout( new QVBoxLayout );
inner->layout()->addWidget( container );
inner->layout()->addItem( new QSpacerItem(1, 1, QSizePolicy::Fixed, QSizePolicy::Expanding) );
QScrollArea* scrollArea;
scrollArea = new QScrollArea;
scrollArea->setWidgetResizable(true);
scrollArea->setFrameShape( QFrame::Box );
scrollArea->setWidget( inner );
setLayout( new QVBoxLayout );
layout()->addWidget( startButton );
layout()->addWidget(scrollArea);
resize( QSize(200, 400) );
}
void FlickTest::addWidgets()
{
container->setUpdatesEnabled(false);
container->layout()->setEnabled(false);
for( int i=0; i<5; i++ )
{
QPushButton* b = new QPushButton;
b->setText( QString("PushButton#%1").arg(i) );
container->layout()->addWidget( b );
}
container->layout()->setEnabled(true);
container->setUpdatesEnabled(true);
QTimer::singleShot( 1000 , this , SLOT(addWidgets()) );
}
Message 2 in thread
On Wednesday 01 August 2007 11:08:26 am Hernan Tylim wrote:
> Hi,
>
> I am having trouble with the implementation of a dialog that I am
> making, and I was hoping some of you could enlighten me in on what is
> going on. Thanks in advance.
>
> My application has a dialog that is visible on the screen, periodically
> some widgets are added to it. Each time new widgets are added the
> contents of the dialog does a little shaking and a flickering.
>
> The attached files contains a class that shows what I am describing.
>
> I will appreciate very much any tip you can offer me to investigate this
> thing further. Thanks again.
>
>
> Regards
> HernÃn Tylim
Try
container->hide() before changes
then
container->show() after changes.
At least that's what I've had to do in the past to reduce flicker.
I don't disable/enable the layout, and I don't use setUpdatesEnabled.
Clint
--
[ signature omitted ]
Message 3 in thread
Hi,
Thanks, but it didn't produce any change. The shaking is still there.
To me the shaking looks like the watching of the layout work in progress.
that would be:
1st. the container is resized so it will have space for one more button.
2nd. because the container has more space, widgets are repositioned and
they MOVE DOWN as space is distributed evenly between them.
3rd. the new button will now be added, so widgets are repositioned
again. They now MOVE UP to make space for the new one.
This move down and up I guess would be the shaking that I can see.
I am assuming that this is what is happening, I don't really know how Qt
works.
But, if I am right I guess I need to do something like calling
setUpdatesEnabled(false) before the layout work starts, and
setUpdatesEnabled(true) when it ends. My problem is that I don't know
when that is. At the end of the method clearly its not.
Thanks
Regards,
HernÃn
clinton@xxxxxxxxxxxx wrote:
> On Wednesday 01 August 2007 11:08:26 am Hernan Tylim wrote:
>> Hi,
>>
>> I am having trouble with the implementation of a dialog that I am
>> making, and I was hoping some of you could enlighten me in on what is
>> going on. Thanks in advance.
>>
>> My application has a dialog that is visible on the screen, periodically
>> some widgets are added to it. Each time new widgets are added the
>> contents of the dialog does a little shaking and a flickering.
>>
>> The attached files contains a class that shows what I am describing.
>>
>> I will appreciate very much any tip you can offer me to investigate this
>> thing further. Thanks again.
>>
>>
>> Regards
>> HernÃn Tylim
>
>
> Try
> container->hide() before changes
> then
> container->show() after changes.
>
> At least that's what I've had to do in the past to reduce flicker.
> I don't disable/enable the layout, and I don't use setUpdatesEnabled.
>
> Clint
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
--
[ signature omitted ]