0

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.

4

3 回答 3

1

您需要将小部件设置到滚动区域并将图片添加到小部件的布局中。检查QScrollArea::setWidget(QWidget *widget)

于 2013-04-11T06:30:59.120 回答
1

你必须:

  • 为您的页面添加布局 ( QVBoxLayout)
  • 将滚动区域添加到该页面布局
  • viewport()为滚动区域中的小部件添加布局( QVBoxLayout)
  • 将您的 QLabels 添加到该视口布局

这样你就不需要在每个标签上调用 setGeometry

于 2013-04-11T01:18:51.940 回答
0

我几乎可以肯定您不能将滚动添加到选项卡小部件,但我的想法只是尝试制作更多可以显示的选项卡并查看默认情况下是否出现滑块。

于 2013-04-11T00:34:59.627 回答