QGridLayout Resizing
-
Hi Forum,
I have a window that has the following layout.
The black boxes are QLabels that are pixmaps of QImages. They are contained within a QGridLayout. I want to be able to click on one of the black boxes and have it become the only blackbox, filling the entire window, and once it is clicked again, return to the multiple view layout. What is the best approach?
I hope this is enough info. (I am on qt 5.10.1)
Kind Regards
-
Hi,
One quick way would be to use a QStackedWidget or QStackedLayout with a QLabel in addition of your grid and on click you change the index and update the content of the label with the image you just clicked on.
-
What do you mean by multiple widgets ?
QStackedWidget and QStackedLayout can contain complex widgets. As show in the documentation, they are just stored on top of each other. What the "contained" widgets contain can be anything you need.
-
After going through the documentation i now have an implementation with that is 6 QStackedLayouts which contain the QPushButton and the QLabel that shows the image. Then the 6 QStackedLayouts are in a QGridLayout and this maintains the 3x2 layout that i was after.
stackedLayout->setStackingMode(QStackedLayout::StackAll);
This allowed me to see the label beneath the button (once i made the button transparent)
If i wish to use the buttons to allow one of the QLabels to become full-screen what is the best way to recreate the layout as i cannot use setLayout(stackedLayout) twice. Should i do something along the lines of:
Delete this->layout(); setLayout(stackedLayout);
Obviously this is not the correct solution but i am unsure how to proceed.
Thanks Again
-
Why not implement my original suggestion ? Put a QLabel and your grid widget in a QStackedLayout and change to the label and back as needed ?