Re: zweites Fenster öffnen - mit loadUi
Verfasst: Freitag 27. Mai 2022, 23:00
Ja. Es ist ein Signal. Wie bei jedem Button.
Seit 2002 Diskussionen rund um die Programmiersprache Python
https://www.python-forum.de/
Code: Alles auswählen
self.label = self.findChild(QLabel, "label_ForgotPassword")
self.label.mousePressEvent = self.openCreateUserWindow
def openCreateUserWindow(self, event):
self.CreateUserWindow = GUICreateUser()
self.CreateUserWindow.show()
Code: Alles auswählen
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel, QLineEdit, QShortcut, QDialog, QWidget
from PyQt5.QtGui import QKeySequence
from PyQt5 import uic, QtWidgets, QtCore, Qt
import sys
import ressource
class GUI(QMainWindow):
def __init__(self):
super().__init__()
# Lade die .ui Datei
uic.loadUi("willkommen.ui", self)
# Setzte das Fenster im Fullscreen Modus
self.showFullScreen()
# Definiere einen Shortcut um das Fenster in die Maximized Modus zu setzten
self.maxiMode = QShortcut(QKeySequence("Ctrl+Q"), self)
self.maxiMode.activated.connect(self.showMaximized)
self.button_Login.clicked.connect(self.openCreateUserWindow)
#self.label = self.findChild(QLabel, "label_ForgotPassword")
#self.label.mouseReleaseEvent = self.openCreateUserWindow
self.label_ForgotPassword.linkActivated.connect(self.openCreateUserWindow)
def openCreateUserWindow(self):
self.CreateUserWindow = GUICreateUser()
self.CreateUserWindow.show()
class GUICreateUser(QWidget):
def __init__(self):
super(GUICreateUser, self).__init__()
uic.loadUi("newuser.ui", self)
# Initialisiere/starte die App
app = QApplication(sys.argv)
GUIWindow = GUI()
GUIWindow.show()
app.exec_()
Code: Alles auswählen
import sys
from PyQt5.QtWidgets import QVBoxLayout,QMainWindow,QApplication,QLabel,QWidget
from PyQt5.QtGui import QPixmap, QPalette
from PyQt5.QtCore import Qt
class QLabelDemo(QWidget) :
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
label1 = QLabel(self)
label2 = QLabel(self)
label3 = QLabel(self)
label4 = QLabel(self)
label1.setText("<font color=yellow>PythonPyQt.com</font>")
label1.setAutoFillBackground(True)
palette = QPalette()
palette.setColor(QPalette.Window,Qt.blue)
label1.setPalette(palette)
label1.setAlignment(Qt.AlignCenter)
label2.setText("<a href='#'>QLabel2</a>")
label3.setAlignment(Qt.AlignCenter)
label3.setToolTip('Hint')
label3.setPixmap(QPixmap("python.png"))
label4.setOpenExternalLinks(True)
label4.setText("https://python.org")
label4.setAlignment(Qt.AlignCenter)
label4.setToolTip('Python.org')
vbox = QVBoxLayout()
vbox.addWidget(label1)
vbox.addWidget(label2)
vbox.addWidget(label3)
vbox.addWidget(label4)
label2.linkHovered.connect(self.linkHovered)
label4.linkActivated.connect(self.linkClicked)
self.setLayout(vbox)
self.setWindowTitle('QLabel Example')
def linkHovered(self):
print('Link hovered')
def linkClicked(self):
print('Link clicked')
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QLabelDemo()
main.show()
sys.exit(app.exec_())
Code: Alles auswählen
from PyQt5.QtWidgets import QMainWindow, QApplication, QLabel, QLineEdit, QShortcut, QDialog, QWidget
from PyQt5.QtGui import QKeySequence
from PyQt5 import uic, QtWidgets, QtCore, Qt
import sys
import ressource
from clickablelabel import QLabelClickable
class GUI(QMainWindow):
def __init__(self):
super().__init__()
# Lade die .ui Datei
uic.loadUi("willkommen.ui", self)
# Setzte das Fenster im Fullscreen Modus
self.showFullScreen()
# Definiere einen Shortcut um das Fenster in die Maximized Modus zu setzten
self.maxiMode = QShortcut(QKeySequence("Ctrl+Q"), self)
self.maxiMode.activated.connect(self.showMaximized)
self.button_Login.clicked.connect(self.openCreateUserWindow)
self.label_ForgotPassword.setOpenExternalLinks(True)
self.label_ForgotPassword.linkActivated.connect(self.linkActivated)
def linkActivated(self):
print('Link active')
def openCreateUserWindow(self):
self.CreateUserWindow = GUICreateUser()
self.CreateUserWindow.show()
class GUICreateUser(QWidget):
def __init__(self):
super(GUICreateUser, self).__init__()
uic.loadUi("newuser.ui", self)
# Initialisiere/starte die App
app = QApplication(sys.argv)
GUIWindow = GUI()
GUIWindow.show()
app.exec_()
Code: Alles auswählen
#!/usr/bin/env python3
import sys
from PyQt5.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
def main():
application = QApplication(sys.argv)
window = QWidget()
layout = QVBoxLayout()
layout.addWidget(
QLabel("<a href='#test'>This is a link</a>", linkActivated=print)
)
window.setLayout(layout)
window.show()
sys.exit(application.exec())
if __name__ == "__main__":
main()
Code: Alles auswählen
<?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>102</width>
<height>29</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string><a href="#test">This is a link</a></string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Code: Alles auswählen
#!/usr/bin/env python3
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.uic import loadUi
def main():
application = QApplication(sys.argv)
window = loadUi("test.ui")
window.label.linkActivated.connect(print)
window.show()
sys.exit(application.exec())
if __name__ == "__main__":
main()
Das stimmt nicht. Man kann schon immer in Qt Slots ohne Argumente verwenden. Ob man auch nur einen Teil der Argumente benutzen kann, weiss ich nicht aus dem Kopf. Aber dein eigenes Beispiel, leicht umformuliert (Ich nutze Qt6):__blackjack__ hat geschrieben: Sonntag 29. Mai 2022, 13:17 Und noch mal: `linkActivated` ist ein Signal das einen Paramter hat. Den muss der Slot auch haben, sonst kann er ja nicht aufgerufen werden.
Code: Alles auswählen
#!/usr/bin/env python3
import sys
from PyQt6.QtWidgets import QApplication, QLabel, QVBoxLayout, QWidget
def no_argument():
print("no_argument")
def main():
application = QApplication(sys.argv)
window = QWidget()
layout = QVBoxLayout()
layout.addWidget(
QLabel("<a href='#test'>This is a link</a>", linkActivated=no_argument)
)
window.setLayout(layout)
window.show()
sys.exit(application.exec())
if __name__ == "__main__":
main()