PDA

View Full Version : Trying to add a scrollArea to contain a long sequence of QLineEdits



feraudyh
26th August 2010, 19:02
Hi
I developped a window with lots of entry fields, so many that the whole thing doesnt fit onto my screen. So I thought one way out would be to create a scroll area and let the user scroll though this.
Trouble is, all my trials have come to nothing. I was hoping to have a minimal change
Here is the constructor for my window:


MyWindow::MyWindow(QMainWindow *parent)
{

this->m_scrollArea = new QScrollArea;
m_scrollArea->setBackgroundRole(QPalette::Light);
setCentralWidget(m_scrollArea);
this->m_frame = new QFrame(this);
this->m_vLayout = new QVBoxLayout(m_frame);
m_scrollArea->setWidget(m_vLayout);
// add entry fields and labels to m_vLayout below.


}

I have of course defined some fields called m_scrollArea, m_frame, etc of the types that you would guess.
When I display my window I just get one big blank area.
Please tell me if you want more detail.
I should add that my window derived from QDialog initially, and then I tried to derive it from QMainWindow in the above code.

norobro
26th August 2010, 20:43
I think that you are adding an empty frame to m_scrollArea. Try moving m_scrollArea->setWidget(m_frame) to below where you add widgets to your layout.

ChrisW67
26th August 2010, 23:45
As norobro alludes, line 9 fails to compile (no matching call). Did you mean:


m_scrollArea->setWidget(m_frame);


You can add the widget to the scroll area after you fill the layout, or you can:


m_vLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);

to handle the dynamic changes in the layout after you have installed the frame in the scroll area. See the detailed description of QScrollArea for stuff about dynamic layouts.

norobro
27th August 2010, 00:28
I figured that was a typo since he said he was getting "one big blank area"

Thanks for the setSizeConstraint() tip!

feraudyh
27th August 2010, 10:27
Yes, I must have copied the version that wouldnt compile. Sorry.

Thanks guys, problem solved.