qlands
11th May 2010, 12:52
Hi,
I have a scrollarea that contains buttons. When I add a button to the area and immediately call ensureWidgetVisible for that button, the scrollarea does not moves to the widget however, if I call ensureWidgetVisible from another button it works. Seem to me that it something related to call this function immediately after adding a button.
Here is a code the mimics the error:
main.cpp
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window;
window.resize(320, 240);
QScrollArea *scrollArea;
QWidget *scrollAreaWidgetContents_2;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout_2;
scrollArea = new QScrollArea(&window);
scrollArea->setGeometry(QRect(1, 1, 231, 61));
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents_2 = new QWidget();
scrollAreaWidgetContents_2->setGeometry(QRect(0, 0, 238, 36));
verticalLayout = new QVBoxLayout(scrollAreaWidgetContents_2);
horizontalLayout_2 = new QHBoxLayout();
verticalLayout->addLayout(horizontalLayout_2);
scrollArea->setWidget(scrollAreaWidgetContents_2);
window.show(); //Will not work
QList<QPushButton *> buttons;
buttons.append(new QPushButton("Button 1",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 2",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 3",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 4",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 5",scrollAreaWidgetContents_2));
int pos;
for (pos = 0; pos<=buttons.count()-1;pos++)
{
buttons[pos]->setGeometry(QRect(80, 330, 112, 26));
}
for (pos = 0; pos<=buttons.count()-1;pos++)
{
horizontalLayout_2->addWidget(buttons[pos]);
}
//window.show(); //Will work
scrollArea->ensureWidgetVisible(buttons[3],0,0);
return a.exec();
}
In this example the ensureWidgetVisible fuction will work depending on where I have the show function.
Any ideas what I am missing? Some refresh before calling ensureWidgetVisible?
Many thanks.
I have a scrollarea that contains buttons. When I add a button to the area and immediately call ensureWidgetVisible for that button, the scrollarea does not moves to the widget however, if I call ensureWidgetVisible from another button it works. Seem to me that it something related to call this function immediately after adding a button.
Here is a code the mimics the error:
main.cpp
#include <QtGui>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget window;
window.resize(320, 240);
QScrollArea *scrollArea;
QWidget *scrollAreaWidgetContents_2;
QVBoxLayout *verticalLayout;
QHBoxLayout *horizontalLayout_2;
scrollArea = new QScrollArea(&window);
scrollArea->setGeometry(QRect(1, 1, 231, 61));
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents_2 = new QWidget();
scrollAreaWidgetContents_2->setGeometry(QRect(0, 0, 238, 36));
verticalLayout = new QVBoxLayout(scrollAreaWidgetContents_2);
horizontalLayout_2 = new QHBoxLayout();
verticalLayout->addLayout(horizontalLayout_2);
scrollArea->setWidget(scrollAreaWidgetContents_2);
window.show(); //Will not work
QList<QPushButton *> buttons;
buttons.append(new QPushButton("Button 1",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 2",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 3",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 4",scrollAreaWidgetContents_2));
buttons.append(new QPushButton("Button 5",scrollAreaWidgetContents_2));
int pos;
for (pos = 0; pos<=buttons.count()-1;pos++)
{
buttons[pos]->setGeometry(QRect(80, 330, 112, 26));
}
for (pos = 0; pos<=buttons.count()-1;pos++)
{
horizontalLayout_2->addWidget(buttons[pos]);
}
//window.show(); //Will work
scrollArea->ensureWidgetVisible(buttons[3],0,0);
return a.exec();
}
In this example the ensureWidgetVisible fuction will work depending on where I have the show function.
Any ideas what I am missing? Some refresh before calling ensureWidgetVisible?
Many thanks.