March 18, 2011

bamboo bamboo
Lab Rat
2 posts

QScrollArea issues

 

Hey everyone,

I’ve been pulling my hair out over the QScrollArea for the past couple of days. What I want to do is this: I want to make an area on my window which will contain a variable number of rows of lineEdit and pushButton widgets. They are laid out in a gridLayout which I have put in a frame. That frame is put into a scrollArea so that when more rows are added, they scan be scrolled to.

I have had zero success using QtDesigner. I drag the scrollArea to the window, drag the frame to the scrollArea and then the gridLayout to the frame but when running, there are no scroll bars.

I have had some success programming it by hand.

  1.    scrollArea = new QScrollArea(tab_2);
  2.    fra_ds_segments = new QFrame;
  3.    gridLayout_2 = new QGridLayout(fra_ds_segments);
  4.  
  5.    fra_ds_segments->setLayout(gridLayout_2);
  6.    scrollArea->setWidget(fra_ds_segments);
  7.  
  8.    scrollArea->setGeometry(10, 210, 855, 201);
  9.  
  10.    <<add lines of lineEdits and pushButtons to gridLayout_2>>
  11.  
  12.    fra_ds_segments->resize(gridLayout_2->sizeHint());

This seems to work OK though I’d rather calculate the size of scrollArea rather than hard-code it. I have hard-coded it to an area which doesn’t need vertical scroll bars for 5 lines but will for any more than that. So as an aside, does anyone know how to calculate the proper width of a scrollArea to hold certain items an not need scroll bars?

The main issue is…how can I use a scrollArea this way within Designer?

Thanks!

3 replies

August 13, 2012

tim.sullivan tim.sullivan
Lab Rat
4 posts

Any progress with this? I’m having the same issue.
My situation also requires that the contents of the scroll area change dynamically. After a button push, widgets are supposed to be added to one of two groupboxes inside the scroll area. I believe I’m taking a fairly typical approach with Qt Designer: – Add Scroll Area to main widget. – Drop groupboxes inside ScrollAreaContents (created automatically by Qt Designer when placing ScrollArea) – Set Scroll Area layout with “Lay Out”>“Lay Out Vertically” – Set main widget layout likewise

Thanks

August 15, 2012

raaghuu raaghuu
Lab Rat
115 posts

Have you tried this [qt-project.org] ?

September 7, 2012

bamboo bamboo
Lab Rat
2 posts

Hi,

I actually ended up giving up and went on to using a QTableView instead. It worked out better for me. Good luck.

tim.sullivan wrote:
Any progress with this? I’m having the same issue.
My situation also requires that the contents of the scroll area change dynamically. After a button push, widgets are supposed to be added to one of two groupboxes inside the scroll area. I believe I’m taking a fairly typical approach with Qt Designer: – Add Scroll Area to main widget. – Drop groupboxes inside ScrollAreaContents (created automatically by Qt Designer when placing ScrollArea) – Set Scroll Area layout with “Lay Out”>“Lay Out Vertically” – Set main widget layout likewise

Thanks

 
  ‹‹ Locking of semi-read-only QVector      QLCDNumber fixed width for numbers ››

You must log in to post a reply. Not a member yet? Register here!