ChaoSXDemon
ChaoSXDemon

Reputation: 910

QScrollArea with multiple QWidgets only shows empty box

I am trying to create a widget that would display some information. Each information would be a QWidget that contains multiple QLabel with text (the information). My idea is to put multiple (array of these) into a QScrollArea so that the user can view them scrolling up and down. The following code:

InfoWidget::InfoWidget(QWidget* parent) : QWidget(parent){
    widgets = new QVector<MarkerInfoWidget*>();
    csv_data = 0;
    csv_velocity = 0;
    labels = 0;
    infoWidgetLayout = new QVBoxLayout(this);
    setLayout(infoWidgetLayout);
    scrollArea = new QScrollArea(this);
    scrollWidgetLayout = new QVBoxLayout(scrollArea);
    scrollArea->setLayout(scrollWidgetLayout);
    infoWidgetLayout->addWidget(scrollArea);
    //Test
    QString name = "TEST";
    for(int i=0; i<10; i++){
        MarkerInfoWidget* markerWidget = new MarkerInfoWidget(name, scrollArea);
        scrollWidgetLayout->addWidget(markerWidget);
        widgets->append(markerWidget);
    }
}

Both MarkerInfoWidget and InfoWidget extends QWidget. What I am getting is simply a box that has very small text:

small Text Example

If I drag it out and re-size it, it display correctly:

Re-sized example

What I have noticed is that if I re-size it too small, it does not generate scrolls. What do I need to fix this?

Upvotes: 2

Views: 1613

Answers (1)

Yester
Yester

Reputation: 683

I guess changing:

scrollArea->setLayout(scrollWidgetLayout);

to sth like:

QFrame* frame = new QFrame(scrollArea);
frame->setLayout(scrollWidgetLayout);
scrollArea->setWidget(frame);

As far as i know you have to put widget into QScrollableArea to make it really scrollable. Setting its layout is probably not the thing you want to do.

Upvotes: 3

Related Questions