This should be easy and I found topics similar to this but I'm still stuck, so I'll
ask in a new thread: How do I get the contents of a tab in a QTabWidget to scroll?
I create a scroll area, set a layout to it and then insert it to a tab
widget. Later, I add widgets to that layout. However, scroll bars never
appear. Instead, the widgets get partially stacked on top of each other.
What am I doing wrong? I'm trying to avoid having to create a custom
widget for each and every tab and then using scrollarea->setWidget() but
is that really the problem?
//in header for base class:
protected:
//in header for this class:
private:
//in constructor for this class:
grid->setAlignment(Qt::AlignLeft | Qt::AlignTop);
scrollarea->setLayout(grid);
tabs->addTab(scrollarea, tr("Look, items!"));
vlayout->addWidget(tabs);
//items get added some time after construction:
SomeItem* item = new SomeItem(this); //not derived from base class, does have a layout
item->setStuff("stuff");
grid ->addWidget(item);
//in header for base class:
protected:
QVBoxLayout* vlayout;
//in header for this class:
private:
QGridLayout* grid;
QTabWidget* tabs;
//in constructor for this class:
tabs = new QTabWidget(this);
grid = new QGridLayout();
grid->setAlignment(Qt::AlignLeft | Qt::AlignTop);
QScrollArea* scrollarea = new QScrollArea(this);
scrollarea->setLayout(grid);
tabs->addTab(scrollarea, tr("Look, items!"));
vlayout->addWidget(tabs);
//items get added some time after construction:
SomeItem* item = new SomeItem(this); //not derived from base class, does have a layout
item->setStuff("stuff");
grid ->addWidget(item);
To copy to clipboard, switch view to plain text mode
Bookmarks