Reputation: 2921
My question is simple : how can I set a QScrollBar in my QScrollArea. I have tested a lot of things but nothing work ... Maybe it's a problem to set a QScrollArea in a QTabWidget ? Here is the code :
void GamesWindow::createTabSucces()
{
std::string nameImg;
_succesPage = new QWidget(_tab);
_tab->addTab(_succesPage, " Succes ");
scrollArea = new QScrollArea(_succesPage);
scrollArea->setBackgroundRole(QPalette::Dark);
scrollArea->setFixedSize(500,500);
/* Integration of QScrollBar */
for (int i = 0; i < 45; i++)
{
nameImg = "img/allAchiv/";
nameImg += intToString(i + 1);
nameImg += ".jpg";
_imgSucc[i] = new QLabel(scrollArea);
_imgSucc[i]->setPixmap(QPixmap(QString(nameImg.c_str())));
_imgSucc[i]->setGeometry((14 + (85 * (i % 5))), 46 + ((i / 5) * 85), 60, 60);
}
}
In fact, I add pictures in a tab where is created a QScrollArea (like 8-9 lines of pictures) but only 5 are visible, the others are hide, because they are at the bottom, out of the defined zone.
Any idea ? Thank's.
Upvotes: 0
Views: 1151
Reputation: 12931
You need to set a widget to your scroll area and add your pictures to the widget's layout. Check QScrollArea::setWidget(QWidget *widget)
Upvotes: 1
Reputation: 3713
You must:
QVBoxLayout
)viewport()
widget in the scroll area (QVBoxLayout
)This way you won't need to call setGeometry on each label
Upvotes: 1
Reputation: 1
I'm almost sure that you can't add scroll to a tab widget but my idea is just to try make more tabs that can be shown and see if the slider comes up by default.
Upvotes: 0