I'm working on a sign in form for a software where the students needs to select their school from the QComboBox (the combobox will show the school's name) and the software will connect to their school's platform. I'm trying to add data (precisely the platform's link) to each item but after reading several posts on stackoverflow, nothing works for me so far.
Here's the QComboBox's part of my sign in form :
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(717, 571)
Form.setWindowFlags(QtCore.Qt.FramelessWindowHint)
Form.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.widget = QtWidgets.QWidget(Form)
self.widget.setGeometry(QtCore.QRect(70, 50, 590, 420))
self.widget.setStyleSheet("QPushButton#pushButton{\n"
" background-color: rgb(23, 171, 103);\n"
" color:rgb(255, 255, 255);\n"
" border-radius:5px;\n"
"}\n"
"")
self.comboBox = QtWidgets.QComboBox(self.widget)
self.comboBox.setGeometry(QtCore.QRect(60, 110, 201, 22))
font = QtGui.QFont()
font.setFamily("Proxima Nova Rg")
self.comboBox.setFont(font)
self.comboBox.setStyleSheet("")
self.comboBox.setEditable(False)
self.comboBox.setCurrentText("Sélectionnez votre établissement")
self.comboBox.setFrame(False)
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.setItemText(0, "Sélectionnez votre établissement")
self.comboBox.addItem("")
self.comboBox.setItemText(1, "LYCEE FRANCAIS RENE DESCARTES")
self.comboBox.addItem("")
self.comboBox.setItemText(2, "IFS SINGAPORE ")
self.comboBox.addItem("")
self.comboBox.setItemText(3, "IFS SINGAPORE - 2")
self.comboBox.addItem("")
self.comboBox.setItemText(4, "LYCEE FRANCAIS INTERNATIONAL DE BANGKOK")
self.comboBox.addItem("")
self.comboBox.setItemText(5, "LYCEE FRANCAIS MARGUERITE DURAS")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Form = QtWidgets.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec())
I've assigned the platform's link as data for each item using this self.comboBox.setItemData
self.comboBox.setItemData(0, "https://platform....")
self.comboBox.setItemData(1, "https://platform....")
self.comboBox.setItemData(2, "https://platform....")
self.comboBox.setItemData(3, "https://platform....")
self.comboBox.setItemData(4, "https://platform....")
self.comboBox.setItemData(5, "https://platform....")