#include <QtGui>
int main(int argc, char *argv[])
{
window.resize(320, 240);
QWidget *scrollAreaWidgetContents_2;
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
);
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();
}
#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();
}
To copy to clipboard, switch view to plain text mode
Bookmarks