PDA

View Full Version : Removing the flicker between widgets?



ganapathi
17th February 2016, 05:19
Hi,

I used the following concepts to display the incoming images scroll from left to right in the main window. The problem I have is there is a flicker between the images that occurs. How do i remove it? I tried using Qt:WA_PaintOnScreen , Qt:WA_NoSystemBackground attributes. But nothing changed.


QScrollArea *scrollArea;
//widget inside scroll area
QWidget *scrollAreaWidgetContents;
//Horizontal Box Layout
QHBoxLayout *horizontalLayout;
//Image loaded to find the width and height to resize the scroll area.
QImage img(QString::fromUtf8("../../../Downloads/red_star.png"));

scrollArea = new QScrollArea(this->centralWidget());
//Adding the size of the scrollbar with the image width
int intWidth=img.width()*2.5+qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)*2;
//Adding the size of the scrollbar with the image Height
int intHeight=img.height()+qApp->style()->pixelMetric(QStyle::PM_ScrollBarExtent)*2;

scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
//Sizing the scroll area and the inside widget
scrollArea->setGeometry(QRect(0, 0,intWidth ,intHeight));
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents = new QWidget();
scrollAreaWidgetContents->setGeometry(QRect(0, 0, intWidth, intHeight));
Making the main window width to the scroll area width
this->setFixedWidth(scrollArea->width());
horizontalLayout = new QHBoxLayout(scrollAreaWidgetContents);
scrollArea->setWidget(scrollAreaWidgetContents);
//Image static array
QString strImages[]= {"../../../Downloads/red_star.png","../../../Downloads/green_star.png","../../../Downloads/yellow_star.png"};
//Add the image in the left side of the previous one (Note the color)
for(int iCount=0; iCount<3; iCount++)
{
QLabel *label = new QLabel(QStringLiteral("label"),scrollAreaWidgetContents);
label->setPixmap(QPixmap(strImages[iCount]));
//Adding the new image to the left of previous image
horizontalLayout->insertWidget(0,label);
}


Thanks in advance

d_stranz
17th February 2016, 17:44
A bunch of lines of code, with absolutely no information about how or where you are using those lines of code. There are lines in there (like #21) that aren't even real code. How should we know why you see flicker?

If this is your actual code (with the incorrect lines commented out) and it is in the constructor, there is nothing in it that would cause flicker to occur. The images are loaded, the horizontal layout is set up, and then the whole thing is painted after a showEvent().

What are you doing when you see flicker occur?