I have problem to access my button and label from my dialog.ui. I am using Python 3.x and QT Designer 5.x.
from PyQt5 import uic, QtWidgets
from PyQt5.QtWidgets import QApplication
Form, Window = uic.loadUiType("dialog.ui") #load ui (GUI) file
app = QApplication([]) #create a QApplication
window = Window()
form = Form()
form.setupUi(window)
def on_click():
# self.qlFreeText.text("hello")
alert = QMessageBox()
alert.setText("You clicked the button!")
alert.exec_()
class Ui(QtWidgets.QMainWindow):
def __init__(self):
super(Ui, self).__init__()
uic.loadUi('basic.ui',self)
# self.ButtonSearch = self.findChild(QtWidgets.QPushButton, 'qpbSearch')
self.ButtonSearch = self.findChild(QtWidgets.QObject, 'qpbSearch')
self.ButtonSearch.button.clicked.connect(self.printButtonPressed)
self.qlFreeText = self.findChild(QWidgets.QLabel, 'qlFreeText')
# self.show()
def printButtonPressed(self):
on_click()
window.show() #show window
app.exec_() #run application until user closes it
dialog.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDateEdit" name="dateStart">
<property name="geometry">
<rect>
<x>50</x>
<y>50</y>
<width>110</width>
<height>22</height>
</rect>
</property>
<property name="displayFormat">
<string>yyyy-MM-dd</string>
</property>
</widget>
<widget class="QDateEdit" name="dateEnd">
<property name="geometry">
<rect>
<x>220</x>
<y>50</y>
<width>110</width>
<height>22</height>
</rect>
</property>
<property name="displayFormat">
<string>yyyy-MM-dd</string>
</property>
</widget>
<widget class="QLabel" name="qlFreeText">
<property name="geometry">
<rect>
<x>120</x>
<y>140</y>
<width>55</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>TextLabel</string>
</property>
</widget>
<widget class="QPushButton" name="qpbSearch">
<property name="geometry">
<rect>
<x>190</x>
<y>220</y>
<width>93</width>
<height>28</height>
</rect>
</property>
<property name="text">
<string>PushButton</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
When I click on the button, nothing happens. What I would like to try is, when I click on the button, than it changes the label text. But currently I can even not use the click on the button.