from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.uic import loadUi
class m(QWidget):
def __init__(self):
self.app = QApplication([])
super().__init__()
loadUi('form.ui', self)
self.CBsettings.currentIndexChanged.connect(self.change)
self.show()
self.app.exec()
def change(self, index):
print(self.CBsettings.itemText(index))
m()
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.uic import loadUi
class m(QWidget):
def __init__(self):
self.app = QApplication([])
super().__init__()
loadUi('form.ui', self)
self.comboBox.currentIndexChanged.connect(self.change)
self.show()
self.app.exec()
def change(self, index):
print(self.comboBox.itemText(index))
m()
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QComboBox" name="comboBox">
<property name="geometry">
<rect>
<x>150</x>
<y>90</y>
<width>69</width>
<height>22</height>
</rect>
</property>
<item>
<property name="text">
<string>Item 1</string>
</property>
</item>
<item>
<property name="text">
<string>Item 2</string>
</property>
</item>
</widget>
</widget>
<resources/>
<connections/>
</ui>
import sys
import os
from PySide2.QtWidgets import QApplication, QWidget
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
class Constructor(QWidget):
def __init__(self):
super(Constructor, self).__init__()
self.load_ui()
self.CBsettings.currentIndexChanged.connect(self.func)
def func(self, index):
# ...
def load_ui(self):
loader = QUiLoader()
path = os.path.join(os.path.dirname(__file__), "form.ui")
ui_file = QFile(path)
ui_file.open(QFile.ReadOnly)
loader.load(ui_file, self)
ui_file.close()
if __name__ == "__main__":
app = QApplication([])
widget = Constructor()
widget.setWindowTitle("Constructor")
widget.show()
sys.exit(app.exec_())