I have a mainwindow of size 480 x 350. The central widget of the main window is a scroll area of dimension 190 x 220. The code for this is as below -
scrollArea
->setObjectName
(QString::fromUtf8("scrollArea"));
scrollArea
->setGeometry
(QRect(210,
20,
191,
221));
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents
= new QWidget();
scrollAreaWidgetContents->setObjectName(
QString::fromUtf8("scrollAreaWidgetContents"));
scrollAreaWidgetContents
->setGeometry
(QRect(0,
0,
187,
217));
scrollArea->setWidget(scrollAreaWidgetContents);
MainWindow->setCentralWidget(centralWidget);
scrollArea = new QScrollArea(centralWidget);
scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
scrollArea->setGeometry(QRect(210, 20, 191, 221));
scrollArea->setWidgetResizable(true);
scrollAreaWidgetContents = new QWidget();
scrollAreaWidgetContents->setObjectName(
QString::fromUtf8("scrollAreaWidgetContents"));
scrollAreaWidgetContents->setGeometry(QRect(0, 0, 187, 217));
scrollArea->setWidget(scrollAreaWidgetContents);
MainWindow->setCentralWidget(centralWidget);
To copy to clipboard, switch view to plain text mode
I have a QLabel which is a child of the scrollarea. The code for this is as shown -
tmp->setText("Custom Label");
tmp
->setGeometry
(QRect( 300,
300,
60,
60));
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QLabel* tmp = new QLabel(scrollAreaWidgetContents);
tmp->setText("Custom Label");
tmp->setGeometry(QRect( 300,300,60,60));
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
To copy to clipboard, switch view to plain text mode
So in the application, the scrollarea must show the scroll bars & user must be able to scroll to the qlabel , which will not be in the displayable area.
But when I run it, the scrollarea does not show the scrollbars & hence its not scrollable. How do i solve this issue? Am I doing something wrong here ?
Bookmarks