First item in gridlayout is in the middle of the Dialog
-
The code gave me the following layout:
grid->addWidget (Title,0,0); grid->addWidget (scroll,1,0); grid->addWidget (test,2,0);
Image of layout
How can I place the "test" text into to scroll area, 0,0 position?
Thank you. -
@gabor53
Honestly I don't understand what exactly you're trying to achieve, but to put "test" into the scroll area you add it to its widget, not next to the scroll area. Something like this:QVBoxLayout * scrollLayout = new QVBoxLayout(viewport); scrollLayout->addWidget(test);
Kind regards.
-
Hi,
The problem is, that the original codeQScrollArea *scroll = new QScrollArea(this); scroll->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOn); scroll->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOn); QWidget *viewport = new QWidget(this); scroll->setWidget (viewport); scroll->setWidgetResizable (true); // Adding layout QLabel *test = new QLabel; test->setText ("test"); QGridLayout *grid = new QGridLayout; grid->addWidget (scroll); Additem::setLayout (grid); grid->addWidget (test);
places the test label to the bottom of the Dialog while the scroll area is right above it. I would like to place the test label to the top left corner of the scroll area. I appreciate any ideas.
Thank you. -
Hi @gabor53 ,
I made solution for you. Download this and try this code. Dropboxhere
@kshegunov has already given you the solution.
Result image . You want "Test " inside the topleft corner of "Scroll" area. But you have coded it in different way. you have made Gridlayout and added "scroll & test" to it. Then how can you get "Test" inside the "scroll" area. Make gridlayoout inside the Scrollarea and add widgets. -
@kshegunov , You have given the 100% correct solution.
@gabor53 seems missed layout inside the Scrollarea. Instead of making layout inside the Scrollarea, @gabor53 has made layout outside the scrollarea and expecting that layout to be inside.
Caution: My point will valid only If gabor53 wants "Test " label inside the scroll area.