QT Creater设计的QwizardPage无法正确设置标题时正确设置几何形状

发布于 2025-01-30 17:09:13 字数 3630 浏览 2 评论 0原文

我正在尝试使用QT Creater设计QwizardPage。

如果我不设置WizardPage的标题,一切都会好起来的。

但是,当我设置标题时,我得到的向导很奇怪。 标题占据了很大的空间,无法完全显示向导页面

我在QT创作者中得到的是:

​net/fqagl.png“ rel =” nofollow noreferrer“>

似乎大小似乎是大小wizardpage小部件的设置与QT创建者中的画布相同,不能为标题提供一些空间。换句话说,在QT创建者中设计QwizardPage并不占用标题所考虑的空间,并获得了错误的几何设置。如何使用QT创建者设计QwizardPage。

以下是如何重现我的问题:

我使用file-&gt; new文件或项目,然后选择qt-&gt; qt designer表单,然后在“选择表单模板”中,我选择qwizardpage 。然后,在我在QT Creater中完成设计后,我使用pyuic5 wizard.ui -o wizard.py将UI文件转换为PYQT代码。我按照此链接向<生成python代码

以下是我的UI文件,这很简单,

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>WizardPage</class>
 <widget class="QWizardPage" name="WizardPage">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>WizardPage</string>
  </property>
  <property name="title">
   <string>This is the tile</string>
  </property>
  <widget class="QGraphicsView" name="graphicsView">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>20</y>
     <width>351</width>
     <height>261</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

我生成的Python文件是:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'qtcchess\wizardpage.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_WizardPage(object):
    def setupUi(self, WizardPage):
        WizardPage.setObjectName("WizardPage")
        WizardPage.resize(400, 300)
        self.graphicsView = QtWidgets.QGraphicsView(WizardPage)
        self.graphicsView.setGeometry(QtCore.QRect(20, 20, 351, 261))
        self.graphicsView.setObjectName("graphicsView")

        self.retranslateUi(WizardPage)
        QtCore.QMetaObject.connectSlotsByName(WizardPage)

    def retranslateUi(self, WizardPage):
        _translate = QtCore.QCoreApplication.translate
        WizardPage.setWindowTitle(_translate("WizardPage", "WizardPage"))
        WizardPage.setTitle(_translate("WizardPage", "This is the tile"))

我要测试的主要文件是:

from PyQt5 import QtCore, QtGui, QtWidgets
from wizardpage import *
from PyQt5.Qt import *
from PyQt5.QtCore import *
import sys


class test_wizard_page(QtWidgets.QWizardPage, Ui_WizardPage):
    def __init__(self, parent):
        super().__init__(parent)
        self.setupUi(self)


class MyWizard(QtWidgets.QWizard):
    def __init__(self):
        super().__init__()

        self.test_wizard_page = test_wizard_page(self)
        self.addPage(self.test_wizard_page)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    wizard = MyWizard()
    wizard.show()
    sys.exit(app.exec_())

I am trying to design QWizardPage using Qt Creater.

Everything goes fine if I don't set the title of the wizardpage.

However, when I set the title, the wizard I got is strange. The title takes a large space and the wizard page can not be shown completely.

What I got in Qt Creator is:

enter image description here

But what I got using the generated python code is, the widget I added can not be show completely:

enter image description here

It seems that the size of the wizardpage widget is set to the same as canvas in the Qt Creator, and doesn't spare some space for the title. In other words, designing QWizardPage in Qt Creator doesn't take the space that the title occupies in consideration, and got a wrong geometry setting. How can I use Qt Creator to design a QWizardPage.

The following is how to reproduce my problem:

I use File->New File or Project, and choose Qt->Qt Designer Form, then in the "choose a form template", I choose QWizardPage. Then after I finish designing in the Qt creater, I convert the ui file to PyQt code by using pyuic5 wizard.ui -o wizard.py. I follow this link to generate python code.

The following is my ui file, which is quite simple

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>WizardPage</class>
 <widget class="QWizardPage" name="WizardPage">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>WizardPage</string>
  </property>
  <property name="title">
   <string>This is the tile</string>
  </property>
  <widget class="QGraphicsView" name="graphicsView">
   <property name="geometry">
    <rect>
     <x>20</x>
     <y>20</y>
     <width>351</width>
     <height>261</height>
    </rect>
   </property>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

My generated python file is:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'qtcchess\wizardpage.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_WizardPage(object):
    def setupUi(self, WizardPage):
        WizardPage.setObjectName("WizardPage")
        WizardPage.resize(400, 300)
        self.graphicsView = QtWidgets.QGraphicsView(WizardPage)
        self.graphicsView.setGeometry(QtCore.QRect(20, 20, 351, 261))
        self.graphicsView.setObjectName("graphicsView")

        self.retranslateUi(WizardPage)
        QtCore.QMetaObject.connectSlotsByName(WizardPage)

    def retranslateUi(self, WizardPage):
        _translate = QtCore.QCoreApplication.translate
        WizardPage.setWindowTitle(_translate("WizardPage", "WizardPage"))
        WizardPage.setTitle(_translate("WizardPage", "This is the tile"))

And my main file for testing is:

from PyQt5 import QtCore, QtGui, QtWidgets
from wizardpage import *
from PyQt5.Qt import *
from PyQt5.QtCore import *
import sys


class test_wizard_page(QtWidgets.QWizardPage, Ui_WizardPage):
    def __init__(self, parent):
        super().__init__(parent)
        self.setupUi(self)


class MyWizard(QtWidgets.QWizard):
    def __init__(self):
        super().__init__()

        self.test_wizard_page = test_wizard_page(self)
        self.addPage(self.test_wizard_page)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    wizard = MyWizard()
    wizard.show()
    sys.exit(app.exec_())

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妳是的陽光 2025-02-06 17:09:13

您必须使用布局经理。右键单击向导页面的空区域,然后从“布置”子菜单中选择垂直或水平布局。

You must use layout managers. Right click on an empty area of the wizard page, and select a vertical or horizontal layout from the "Lay out" submenu.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文