2 Attachment(s)
Using click() on buttonWidget to change the current tab on tabWidget
?Good afternoon from Thailand
I would like to have some help which it's about the socket in Qt Designer for python.
So my question is, is it possible to use click() on buttonWidget to change the current tab on tabWidget ?
(I'm trying to find some solution in the forum but not found yet)
Thank you in advance for helps
Zingzing
Attachment 13029
Attachment 13030
Re: Using click() on buttonWidget to change the current tab on tabWidget
In C++ it is possible to connect to a lambda function which would then call the setCurrentIndex() method.
Maybe that is also possible in Python.
Cheers,
_
Re: Using click() on buttonWidget to change the current tab on tabWidget
If it is only one or two buttons then use one of the two methods, explicit slot method or lambda function, shown in this example:
Code:
import sys
from PyQt5.
QtGui import
QIcon
def __init__(self):
super().__init__()
self.title = 'Test'
self.left = 10
self.top = 10
self.width = 640
self.height = 480
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.
tabWidget.
addTab(QWidget(),
"Page 1") self.
tabWidget.
addTab(QWidget(),
"Page 2") self.button1.clicked.connect(lambda: self.tabWidget.setCurrentIndex(0))
self.button2.clicked.connect(self.button2_clicked)
self.layout.addWidget(self.tabWidget)
self.layout.addWidget(self.button1)
self.layout.addWidget(self.button2)
self.setLayout(self.layout)
self.show()
def button2_clicked(self):
self.tabWidget.setCurrentIndex(1)
if __name__ == '__main__':
ex = App()
sys.exit(app.exec_())
If you have several buttons that select different tabs in the tab widget then you could connect the buttons clicked() signals into a QSignalMapper, give each input an integer mapping, and connect the mapper's output signal to the tab widget's setCurrentIndex() slot.