Looking for advice on how to make one widget be displayed over another



  • Hi All;

    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.

    any ideas?



  • 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?



  • Maybe QStackedLayout will help you?



  • cool@Denis :)



  • chetankjain Wrote:

    "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.



  • Here is the layout of the gui if it helps. I also have a question on handling resizing of the gui which i will ask later.

    !http://i1209.photobucket.com/albums/cc384/seckley/Drawing1.jpg(Gui layout)!



  • [quote author="TwoGunBerg" date="1284555514"]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?
    [/quote]

    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;
    ui->frame->setLayout(vboxlayout);

    // lbl occupies whole frame
    QLabel *lbl = new QLabel("Picture Label!");
    vboxlayout->addWidget(lbl);
    
    // lbltop is the child of lbl
    QLabel *lbltop = new QLabel("Picture Info Label!", lbl);
    lbltop->setGeometry(50,50,50,50);
    lbltop->show();
    
    qDebug() << "Picture Label: " << lbl->rect() << ", " << lbl->size();
    qDebug() << "Picture Info Label: " << lbltop->pos();
    

    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.