Overlapping frame (or widget) ?



  • Hi,
    sorry for noob question.
    I've two frame with the same size and position (overlapped). On frame_1 there is a button called btn1 . On frame_2 there is another button called btn2.
    I want to achieve this result:
    When a user click on btn1 (the frame on top) , the frame_1 disappear and frame_2 appear. When a user click on btn2 the frame_2 disappear and frame_1 appear.
    Can i achieve this result with frame or widget? ( I've tried with setVisible function without success).
    Thanks, Giovanni.


  • Moderators

    Sounds like a job for QStackedWidget:

    QStackedWidget* foo = new QStackedWidget();
    foo->addWidget(frame_1);
    foo->addWidget(frame_2);
    connect(frame_1->btn1, &QPushButton::clicked, [=]{ foo->setCurrentIndex(1); });
    connect(frame_2->btn2, &QPushButton::clicked, [=]{ foo->setCurrentIndex(0); });
    


  • @Chris-Kawa said:

    nect(fra
    Thanks a lot Chris, very clean solution!
    I've found that the issue was with the designer. When i put one widget over another the designer puts the first widget inside the second. I will a try your solution that sound a lot better.
    Thanks again.
    Giovanni.


Log in to reply
 

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