在QStackedWidget中显示箭头

时间:2018-05-25 20:43:28

标签: python python-3.x pyqt qt-designer

我在GUI使用Qt-DesignerPyqt5进行python 3.6.3

GUI有一个QStackedWidget,有2页。每个页面都有一个箭头,因此用户可以在它们之间切换(如Qt-Designer所示(参见下面的pciture))。

问题是,当我使用uipy转换为pyuic5然后运行py代码时,箭头会切换QStackedWidget的页面消失了。

运行py代码时如何显示箭头?

代码:

# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_Dialog(object):
    def setupUi(self, Dialog):
        Dialog.setObjectName("Dialog")
        Dialog.resize(314, 216)
        self.stackedWidget = QtWidgets.QStackedWidget(Dialog)
        self.stackedWidget.setGeometry(QtCore.QRect(40, 40, 211, 101))
        self.stackedWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
        self.stackedWidget.setStyleSheet("selection-background-color: rgb(255, 255, 127);\n"
"background-color: rgb(154, 154, 154);\n"
"border-color: rgb(255, 0, 0);\n"
"selection-color: rgb(85, 255, 0);")
        self.stackedWidget.setFrameShape(QtWidgets.QFrame.Box)
        self.stackedWidget.setFrameShadow(QtWidgets.QFrame.Plain)
        self.stackedWidget.setLineWidth(1)
        self.stackedWidget.setMidLineWidth(2)
        self.stackedWidget.setObjectName("stackedWidget")
        self.page = QtWidgets.QWidget()
        self.page.setObjectName("page")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.page)
        self.lineEdit_2.setGeometry(QtCore.QRect(80, 40, 113, 25))
        self.lineEdit_2.setMinimumSize(QtCore.QSize(113, 0))
        self.lineEdit_2.setStyleSheet("background-color: rgb(255, 255, 255);")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label = QtWidgets.QLabel(self.page)
        self.label.setGeometry(QtCore.QRect(10, 40, 68, 19))
        self.label.setMinimumSize(QtCore.QSize(68, 0))
        self.label.setObjectName("label")
        self.stackedWidget.addWidget(self.page)
        self.page_2 = QtWidgets.QWidget()
        self.page_2.setObjectName("page_2")
        self.lineEdit = QtWidgets.QLineEdit(self.page_2)
        self.lineEdit.setGeometry(QtCore.QRect(80, 40, 113, 25))
        self.lineEdit.setMinimumSize(QtCore.QSize(113, 0))
        self.lineEdit.setStyleSheet("background-color: rgb(255, 255, 0);\n"
"border-color: rgb(0, 0, 255);")
        self.lineEdit.setObjectName("lineEdit")
        self.label_2 = QtWidgets.QLabel(self.page_2)
        self.label_2.setGeometry(QtCore.QRect(10, 40, 68, 19))
        self.label_2.setMinimumSize(QtCore.QSize(68, 0))
        self.label_2.setObjectName("label_2")
        self.stackedWidget.addWidget(self.page_2)

        self.retranslateUi(Dialog)
        self.stackedWidget.setCurrentIndex(0)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def retranslateUi(self, Dialog):
        _translate = QtCore.QCoreApplication.translate
        Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
        self.label.setText(_translate("Dialog", "I/P1 ="))
        self.label_2.setText(_translate("Dialog", "I/P2 ="))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    Dialog = QtWidgets.QDialog()
    ui = Ui_Dialog()
    ui.setupUi(Dialog)
    Dialog.show()
    sys.exit(app.exec_())

QStackedWidget

的正确视图

enter image description here

0 个答案:

没有答案