So i have a main layout called the ‘vboxmain’. And the program has two states: blackjack and poker. For both I have a button. In this vboxmain I have an upper part, which covers most of the program, and is the same for both games, but I also have a bottom part which should display different parts for both games. For example, poker game should hold five QCheckBoxes and one button. As for the blackjack game i need simply two buttons. I created both of these bottom layouts as QVBoxLayouts. So now i have:
BlackjackiValikud = new QVBoxLayout; //for blackjack
Pokkerivalikud = new QVBoxLayout; //for poker
And I tried creating two button actions like this:
void mainwindow::BlackJack_clicked(){
vboxmain->removeItem(Pokkerivalikud);
vboxmain->addItem(BlackjackiValikud);
}
void mainwindow::Poker_clicked(){
vboxmain->removeItem(BlackjackiValikud);
vboxmain->addItem(Pokkerivalikud);
}
Buttons are connected like this:
connect(BlackjackButton, SIGNAL(clicked()), this, SLOT(BlackJack_clicked()));
connect(PokerButton, SIGNAL(clicked()), this, SLOT(Poker_clicked()));
But currently it’s not working and I can’t figure out a way to do this, so I’m asking for help. This is probably not the best way to do this either but I don’t know any other ways. So I could use some help on how to make this work with whatever solution – so that with both buttons I can change the bottom part of my vboxmain as needed.
I’m open to solutions.
What do you mean by it is not working?
You have to make sure that the layout are enabled when you add them (via
QLayout::setEnabled ( bool enable)) or that widget are visible (viaQWidget::show()). In general you have to manuable make visible items which are added to a widget which is already visible…An alternative would be to use a QStackedLayout to display either. You have a widget
pokerfor the poker view and a widgetblackjackfor the black jack view. On button push you use either