我正在創建一個最初顯示登錄和註冊按鈕的應用程序。 點擊登錄我想顯示另一個屏幕(或對話框),這將允許用戶輸入用戶名和密碼。單擊按鈕創建新對話框
,我想隱藏第一個對話框,當第二個對話框已經出現了,但沒能做到這一點。(就像我們在Facebook的信使)
我們能否通過連接到點擊的信號打開一個新的對話框登錄按鈕在Qt dsigner本身?
我已經設計了第一個屏幕在Qt Designer中,轉換是的.ui文件的.py然後導入它在main.py
main.py
import sys
from Pyside.QtGui import *
from Pyside.QtCore import *
from firstscreen import Ui_Dialog
class MainDialog(QDialog, Ui_Dialog):
def __init__(self, parent=None):
super(MainDialog, self).__init__(parent)
self.setupUi(self)
self.Login.clicked.connect(self.showsecondscreen)
def showsecondscreen(self):
newScreen = QDialog(self)
newScreen.show(self)
app = QApplication(sys.argv)
form = MainDialog()
form.show()
app.exec_()
firstscreen.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>322</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>My App</string>
</property>
<widget class="QPushButton" name="Login">
<property name="geometry">
<rect>
<x>110</x>
<y>110</y>
<width>98</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Login</string>
</property>
</widget>
<widget class="QPushButton" name="Signup">
<property name="geometry">
<rect>
<x>110</x>
<y>150</y>
<width>98</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>Signup</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>
是self.hide()正在工作 – Patrick
那麼請標記爲答案。 – St0fF