looking for advice on how to make one widget be displayed over another
here is my dilema. I am displaying a picture in a widget called PictureLabel that has been derived from QLabel, after the user chooses which to display. the derived PictureLabel’s sole purpose is to be able to have a clicked signal. when the PictureLabel is clicked i want to have a widget with information on the picture to appear super imposed over the Picture that is being displayed. i have all the classes set to go but i’m having a problem trying to figure out how to have the info appear.
The basic layout i have is a QVBoxlayout that contains the PictureLabel and a menucontroller widget. The menucontroller contains a QHBoxlayout that has an albummenu, a picturemenu and a QPushButon ( the QPushButton is only visible when Picturemenu is visible). When the user selects an album from the album menu, it disappears and the picture menu will appear with images from the selected album.
“When you add 2 widgets at the same position (overlap), the second one has a higher z-order and comes on top of the first. Based on your logic you can then use show() or hide() calls to make a specific widget appear or disappear. Would that solve your problem”
How do add two widgets to the same position when you are using a QVBoxlayout? doesn’t a QVBoxlayout by nature put each widget added at a different position?
Denis Kormalev wrote:
“Maybe QStackedLayout will help you?”
I thought about that but unfortunately only one of the stacked panes can be shown at a time and i need to have the picture showing below the infowidget when it pops up. The infowidget will be smaller than the picture displayed.
QVBoxlayout? doesn't a QVBoxlayout by nature put each widget added at a different position?How do add two widgets to the same position when you are using a
You can set the second one as the child of the first anytime. This code shows how to do it.. would that solve your problem?
- QVBoxLayout *vboxlayout = new QVBoxLayout;
- // lbl occupies whole frame
- // lbltop is the child of lbl
- qDebug() << "Picture Label: " << lbl->rect() << ", " << lbl->size();
- qDebug() << "Picture Info Label: " << lbltop->pos();