I'm trying to mimic the tab button behaviour with buttons from another class.
So that when I click the Orders or History button the corresponding tab is selected.
ATM the code I have seems to work in so far as updating the currentIndex attribute as it prints correctly (0 for Orders and 1 for History).
However this change does not seem to reflect in the window, am I right in thinking this is an 'update widget' problem? If so how do I 'refresh' it? If not am I missing some fundamental concept?
I've slimmed the code as much as I could...
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
Application = QApplication(sys.argv)
class Window(QWidget):
def __init__(self):
super().__init__()
# Layout #
Layout = QVBoxLayout()
Layout.addLayout(LayoutTabButtons())
Layout.addWidget(Tabs())
self.setLayout(Layout)
self.show()
class Tabs(QTabWidget):
def __init__(self):
super().__init__()
# Children #
self.addTab(QLabel('This Is The Orders Page'),'Orders')
self.addTab(QLabel('This Is The History Page'),'History')
# Connections #
InstanceButtonOrders = ButtonOrders(self)
InstanceButtonHistory = ButtonHistory(self)
def ChangeIndex(self, Input):
self.setCurrentIndex(Input)
print(self.currentIndex()) # <--- Prints Correctly
class LayoutTabButtons(QHBoxLayout):
def __init__(self):
super().__init__()
# Children #
self.addWidget(ButtonOrders(Tabs()))
self.addWidget(ButtonHistory(Tabs()))
class ButtonOrders(QPushButton):
def __init__(self, Tabs):
super().__init__()
# Content #
self.setText('Orders')
# Connections #
self.clicked.connect(lambda: self.SetIndex(Tabs))
def SetIndex(self,Tabs):
Tabs.ChangeIndex(0)
class ButtonHistory(QPushButton):
def __init__(self, Tabs):
super().__init__()
# Content #
self.setText('History')
# Connections #
self.clicked.connect(lambda: self.SetIndex(Tabs))
def SetIndex(self,Tabs):
Tabs.ChangeIndex(1)
InstanceWindow = Window()
sys.exit(Application.exec_())
As an aside my 1st instinct was to go through the PyQt5 module files in order to get a clue as to how the default behaviour is done, but as Qt is written in C++ that wasn't an option here.