Answer the question
In order to leave comments, you need to log in
How to make a tab inactive when a radioButton is selected?
Tell me please. There is a main form (mainForm.py), a QTabWidget with 4 tabs is created inside. Tab code - class TabPage. How in TabPage, when you click on the button, make the current tab inactive?
mainForm.py:
import mainFormUI
import tabPage
from PyQt5 import QtWidgets, QtCore, QtGui
class MainForm(QtWidgets.QWidget):
def __init__(self, user, id, course):
QtWidgets.QWidget.__init__(self)
self.ui = mainFormUI.Ui_Dialog()
self.ui.setupUi(self)
self.user = user
self.id = id
self.course = course
self.ui.curUsr.setText(self.user + " (" + self.id + ", " + self.course + " курс)")
self.tabWidget = QtWidgets.QTabWidget(self)
for i in range(1, 5):
self.tabWidget.addTab(tabPage.TabPage(i), str(i))
self.grid = QtWidgets.QGridLayout()
self.grid.setAlignment(QtCore.Qt.AlignCenter)
self.grid.addWidget(self.ui.endBtn)
self.vbox = QtWidgets.QVBoxLayout()
self.vbox.setMenuBar(self.main_menu())
self.vbox.addWidget(self.ui.curUsr)
self.vbox.addWidget(self.tabWidget)
self.vbox.addLayout(self.grid)
self.setLayout(self.vbox)
self.show()
import mainForm
from PyQt5 import QtWidgets, QtCore, QtGui
class TabPage(QtWidgets.QWidget):
def __init__(self, index, parent=None):
super().__init__(parent)
#QtWidgets.QWidget.__init__(self)
self.index = index
self.qLbl = QtWidgets.QLabel('question 1')
self.rb1 = QtWidgets.QRadioButton('rb1')
self.cb = QtWidgets.QPushButton('Подтвердить')
self.grid = QtWidgets.QGridLayout()
self.grid.setAlignment(QtCore.Qt.AlignCenter)
self.grid.addWidget(self.cb)
self.hbox = QtWidgets.QHBoxLayout()
self.hbox.addLayout(self.grid)
self.bg = QtWidgets.QButtonGroup()
self.bg.addButton(self.rb1, id=1)
self.bg.buttonClicked.connect(self._on_radio_button_clicked)
self.vbox = QtWidgets.QVBoxLayout()
self.vbox.addWidget(self.qLbl)
self.vbox.addWidget(self.rb1)
self.vbox.addLayout(self.hbox)
self.setLayout(self.vbox)
def _on_radio_button_clicked(self, button):
self.parent().tableWidget.setTabEnabled(self.index-1, False) # ???
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question