I'm trying to use a pyqt6 combo box to load a selection into a variable so I can use it elsewhere. Not sure why I'm getting the following error:
Traceback (most recent call last):
File "e:\python_projects\pac_org\main2.py", line 115, in <module>
main()
File "e:\python_projects\pac_org\main2.py", line 111, in main
ex = Example()
File "e:\python_projects\pac_org\main2.py", line 9, in __init_ _self.initUI()
File "e:\python_projects\pac_org\main2.py", line 74, in initUI grid.addWidget(lblPStyleR, 3, 0, color('red'))
TypeError: arguments did not match any overloaded call:
addWidget(self, QWidget): argument 1 has unexpected type 'str'
addWidget(self, QWidget, int, int, alignment: Qt.AlignmentFlag = Qt.Alignment()): argument 1 has unexpected type 'str'
addWidget(self, QWidget, int, int, int, int, alignment: Qt.AlignmentFlag = Qt.Alignment()): argument 1 has unexpected type 'str'
I've tracked the issue to the line
grid.addWidget(lblPStyleR, 3, 0)
This line is supposed to input the value of the variable self.tstPTypeR into Row 3 Column 0. I've tried entering self tstPTypeR directly into the grid.addWidget statement but get the same error. Not sure what I'm missing. Tried adjusting the super().__init__
statement with no results. Complete code below:
from PyQt6.QtWidgets import (QWidget, QLabel, QLineEdit, QGridLayout, QApplication, QComboBox)
import sys
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.tstPStyleR = str("0")
self.tstPTypeR = str("0")
#self.strPLoc = 0
#self.strAIMVer = 0
lblPSN = QLabel("PAC Serial Number: ")
ledPSN = QLineEdit()
lblPType = QLabel("PAC Type: ")
cboPType = QComboBox(self)
cboPType.addItems(["Single", "Double", "Triple"])
cboPType.textActivated[str].connect(self.onPTypeActivate)
self.lblPTypeR = QLabel("Single", self)
lblPStyle = QLabel("PAC Style: ")
cboPStyle = QComboBox(self)
cboPStyle.addItems(["3x Fuse, 1x 48v", "3x Fuse, 2x 48v", "0x Fuse, 1x 48v", "0x Fuse, 2x 48v"])
cboPStyle.textActivated[str].connect(self.onPStyleActivate)
self.lblPStyle = QLabel("3x Fuse, 1x 48v", self)
lblPLoc = QLabel("PAC Location: ")
cboPLoc = QComboBox(self)
cboPLoc.addItems(["PAC Cell", "PAC Cell: Repair", "Blue Line", "Frame"])
cboPLoc.textActivated[str].connect(self.onPLocActivate)
self.lblPLoc = QLabel("PAC Cell")
lblAIMSN = QLabel("AIM SN: ")
ledAIMSN = QLineEdit()
lblAIMVer = QLabel("AIM Version: ")
cboAIMVer = QComboBox(self)
cboAIMVer.addItems(["GREEN 1.4", "RED 2.0", "RED 3.0"])
cboAIMVer.textActivated[str].connect(self.onAIMVerActivate)
self.label = QLabel("GREEN 1.4", self)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(lblPSN, 1, 0)
grid.addWidget(ledPSN, 1, 1)
grid.addWidget(lblPType, 1, 2)
grid.addWidget(cboPType, 1, 3)
grid.addWidget(self.lblPTypeR, 1, 4)
grid.addWidget(lblPStyle, 1, 5)
grid.addWidget(cboPStyle, 1, 6)
grid.addWidget(self.lblPStyle, 1, 7)
grid.addWidget(lblPLoc, 1, 8)
grid.addWidget(cboPLoc, 1, 9)
grid.addWidget(self.lblPLoc, 1, 10)
grid.addWidget(lblAIMSN, 2, 0)
grid.addWidget(ledAIMSN, 2, 1)
grid.addWidget(lblAIMVer, 2, 2)
grid.addWidget(cboAIMVer, 2, 3)
grid.addWidget(self.label, 2, 4)
self.setLayout(grid)
lblPStyleR = str(self.tstPStyleR)
#lblPTypeR = self.strPTypeR
#lblPLocR = self.strPLoc
#lblAIMVerR = self.strAIMVer
grid.addWidget(lblPStyleR, 3, 0)
#grid.addWidget(self.strPTypeR, 3, 1)
#grid.addWidget(lblPLocR, 3, 2)
#grid.addWidget(lblAIMVerR, 3, 3)
self.setGeometry(300, 300, 350, 300)
self.setWindowTitle("Stratacache PAC Manager")
self.show()
def onPStyleActivate(self, text):
self.tstPStyleR = text
print(self.tstPStyle)
self.lblPStyle.setText(text)
self.lblPStyle.adjustSize()
return self.tstPStyleR
def onPTypeActivate(self, text):
self.tstPTypeR = text
print(self.tstPTypeR)
self.lblPTypeR.setText(text)
self.lblPTypeR.adjustSize()
def onPLocActivate(self, text):
self.strPLoc = text
self.lblPLoc.setText(text)
self.lblPLoc.adjustSize()
return self.strPLoc
def onAIMVerActivate(self, text):
self.strAIMVer = text
self.label.setText(text)
self.label.adjustSize()
return self.strAIMVer
def main():
app = QApplication(sys.argv)
ex = MainWindow()
sys.exit(app.exec())
if __name__ == '__main__':
main()
Thanks for the assistance.