tags:

views:

303

answers:

2

I'm trying to add scrolling to a drag and drop example source that I modified. The example simply draws several draggable QLabel widgets. I was modifying it in a way that a larger number of various different length widgets would be created.

I made a class that would be called by main and would contain the scrolling widget, that in turn would contain the original widget that draws the QLabels. The only method on this class is the constructor, and here's its implementation:

layoutWidget::layoutWidget(QWidget *parent) : QWidget(parent){
    QScrollArea *scroll = new QScrollArea();
    QVBoxLayout *layout = new QVBoxLayout();

    //widget that draws the draggable labels
    Widget *w = new Widget();

    scroll->setWidget(w);
    scroll->setBackgroundRole(QPalette::Light);

    layout->addWidget(scroll);    

    setLayout(layout);
}

I'm using setMinimumSize() on the Widget constructor. When I run the program, only what's inside the area defined by setMinimumSize() is drawn, the rest is clipped off. Am I missing something?

+1  A: 

Your widget most likely needs to resize itself to the full size to show its contents. What is probably happening is that the minimum size you set is the only size it is getting, so it uses that. I would suggest adding a layout to the widget to make it size dynamically based on its children, but I don't think that would work very well with draggable contents.

Caleb Huitt - cjhuitt
but aren't I doing that already?
David McDavidson
oh I see what you mean now.
David McDavidson
A: 

The minimum size of the widget inside the scroll area was smaller than its content, so only what's inside that area is drawn. I used larger values for setMinimumSize() and the problem was solved.

David McDavidson