How to identify which tab is selected



  • I have a QMainWindow with a QPushButton and a QTabWidget formed by 4 tabs:
    in each tab there are 5 QRadioButton (for a total of 20)

    When the QMainWindow starts, all the QRadioButton are deselected, but if the user select one QRadioButton from the first tab, then click the third tab and select another QRadioButton when he pushes the QPushButton I don't know which QRadioButton is selected.

    How can I determine the current tab so I can know the QRadioButton associated with ?
    Is it possible when a user switch between the tabs to deselect all the QRadioButton in the current tab ?

    I'm a totally newbie and I'm using pyside.

    Thanks for your help.



  • Hi, you may determine the current tab by using ui->tab->currentIndex().
    The QRadioButtons can be selected with *ui->tab->findChildren<QRadioButton >();



  • Thanks for your reply. I think now to be able to know which is the current tab when the user press the button:

    @def push_button_clicked(self):
        if self.tabWidget.currentIndex() == 0:
            # check all radioButton from current tab
            print 'user on first tab', self.tabWidget.currentIndex()
        elif self.tabWidget.currentIndex() == 1:
            # check all radioButton from current tab
            print 'user on second tab', self.tabWidget.currentIndex()
        elif self.tabWidget.currentIndex() == 2:
            # check all radioButton from current tab
            print 'user on third tab', self.tabWidget.currentIndex()
        elif self.tabWidget.currentIndex() == 3:
            # check all radioButton from current tab
            print 'user on fourth tab', self.tabWidget.currentIndex()@
    

    Is there a way to deselect the radioButton ?



  • Yes, you can use

    @
    ui->radioButton.setChecked(false);
    @


Log in to reply
 

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