Help at QStackedWidget

I am using QStackedWidget on my mainWindow. FirstPageWidget on stackedWidget contains 3 buttons. Now, if I click the first button on the first page, I want the stackedWidget to display the widget of the 2nd page. Details below

I tried to connect like this in my mainwindow

connect(firstPageWidget->button1,SIGNAL(clicked()),stackWidget,SLOT(setCurrentIndex(int)));

Now I want to know how to pass the index number value to stackWidget to set currentIndex?

If my question is not very clear, tell me what I will explain more.

+3
source share
3 answers

You probably need to use the QSignalMapper class:

QSignalMapper mapper = new QSignalMapper(); // don't forget to set the proper parent
mapper->setMapping(firstPageWidget->button1, 2); // 2 can be replaced with any int value
connect(firstPageWidget->button1, SIGNAL(clicked()), mapper, SLOT(map()));
connect(mapper, SIGNAL(mapped(int)), stackWidget, SLOT(setCurrentIndex(int)));
+5
source

QListWidget, . QListWidget QListWidget::currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous ). , ... on_change_widget( QListWidgetItem *current, QListWidgetItem *previous ), SIGNAL currentItemChanged:

connect( my_list_widget,
         SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem *)),
         this,
         SLOT(on_change_widget(QListWidgetItem *, QListWidgetItem *))
       );

.

, .

, , QSignalMapper.

0

You can also use QButtonGroup and set the correct identifier for each button, then connect the QButtonGroup signal QButtonGroup::buttonClicked(int)with the widget slot layerQStackedWidget::setCurrentIndex(int)

0
source

Source: https://habr.com/ru/post/1740726/


All Articles