【发布时间】:2019-01-24 15:51:52
【问题描述】:
我正在开发一个小型测试程序(翻译器)以进入 QtDesigner。 这是它在设计器中的样子:
如您所见,两个组合框具有不同的宽度 - 我没有手动更改任何宽度值,我只更改了 alingment 和布局。除了文本之外,整个左半部分和右半部分是相同的,除了左侧文本字段是 QTextEdit 而右侧是 QTextBrowser。
似乎也与组合框中存储的项目无关,遗憾的是我无法手动更改项目的大小,因为它们似乎绑定在布局中。
谁能告诉我这里发生了什么?这不是一个大问题,但它看起来很痛苦。
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>711</width>
<height>402</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>790</width>
<height>402</height>
</size>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget">
<property name="minimumSize">
<size>
<width>663</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>795</width>
<height>414</height>
</size>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="InputLayout">
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="Label_Input">
<property name="text">
<string>Input:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextEdit" name="Text_Input">
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
<property name="html">
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="Combo_Input">
<property name="enabled">
<bool>true</bool>
</property>
<item>
<property name="text">
<string>Auto</string>
</property>
</item>
<item>
<property name="text">
<string>en</string>
</property>
</item>
<item>
<property name="text">
<string>de</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<layout class="QVBoxLayout" name="ButtonLayout">
<item>
<widget class="QPushButton" name="Button_Translate">
<property name="text">
<string>=></string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="Button_Swap">
<property name="text">
<string><-></string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2">
<layout class="QVBoxLayout" name="OutputLayout">
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="Label_Output">
<property name="text">
<string>Translated result:</string>
</property>
</widget>
</item>
<item>
<widget class="QTextBrowser" name="Text_Output">
<property name="html">
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
p, li { white-space: pre-wrap; }
</style></head><body style=" font-family:'MS Shell Dlg 2'; font-size:8.25pt; font-weight:400; font-style:normal;">
<p align="center" style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><br /></p></body></html></string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="Combo_Output">
<item>
<property name="text">
<string>en</string>
</property>
</item>
<item>
<property name="text">
<string>de</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
我在尝试解决此问题时偶然发现的另一个大问题是,在打破布局并设置其最小尺寸后,我无法再更改组合框的对齐方式 - 即使在我 ctrl+z 回到以前在哪里!
【问题讨论】:
-
请将整个ui文件贴出来,方便其他人在qt设计器中测试。
-
完成了,希望你能在那里找到一些东西......
-
我无法使用您发布的 ui 文件复制此内容。对我来说,这两个组合框会扩展以填充可用空间。您使用的是什么版本的 qt,在哪个平台上?
-
是的,看来我急于回家我粘贴了一个稍微错误的 .ui 文件,如果您将两个组合框设置为右对齐,您将获得与我发布的图像中的相同
标签: python qt user-interface pyqt5 qt-designer