//widget inside scroll area
//Horizontal Box Layout
//Image loaded to find the width and height to resize the scroll area.
QImage img
(QString::fromUtf8("../../../Downloads/red_star.png"));
//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);
}
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);
}
To copy to clipboard, switch view to plain text mode
Bookmarks