我正在使用QtDesigner为PyQT5应用程序创建一个uifile。我在ButtonGroup中有一组QRadioButtons。我遇到的问题是,当我保存到uifile时,保存按钮的顺序会影响布局。当我打印每个按钮的QRadioButton.geometry()时,值是正确的,但它们不会在最终的GUI中以这种方式布局,除非我编辑uifile并重新排序小部件。
这是所需的布局:
rb6 rb7 rb8
rb3 rb4 rb5 rb9
rb0 rb1 rb2
在Notepad ++中搜索“QRadioButton”显示按钮保存的顺序:
Search "RadioButton" (10 hits in 1 file)
E:\FileNamingWidget.ui (10 hits)
Line 543: <widget class="QRadioButton" name="Rb8">
Line 565: <widget class="QRadioButton" name="Rb0">
Line 590: <widget class="QRadioButton" name="Rb9">
Line 618: <widget class="QRadioButton" name="Rb7">
Line 640: <widget class="QRadioButton" name="Rb3">
Line 662: <widget class="QRadioButton" name="Rb4">
Line 687: <widget class="QRadioButton" name="Rb5">
Line 709: <widget class="QRadioButton" name="Rb2">
Line 731: <widget class="QRadioButton" name="Rb6">
Line 753: <widget class="QRadioButton" name="Rb1">
然后将无线电按钮布置成这样:
rb8 rb3 rb0
rb4 rb5 rb6 rb2
rb1 rb9 rb7
为什么呢?除了在用uic.loadUI()
将它加载到我的Python程序之前手动编辑uifile,我该如何解决这个问题呢?
感谢您的帮助。
以下是来自uifile的QRadioButton小部件的保存顺序:
<widget class="QRadioButton" name="Rb8">
<property name="geometry">
<rect>
<x>107</x>
<y>121</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Right Rear</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb0">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>62</x>
<y>159</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Left Front</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb9">
<property name="geometry">
<rect>
<x>130</x>
<y>140</y>
<width>13</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Multi Aspect</string>
</property>
<property name="text">
<string/>
</property>
<property name="shortcut">
<string/>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb7">
<property name="geometry">
<rect>
<x>84</x>
<y>121</y>
<width>17</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Rear</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb3">
<property name="geometry">
<rect>
<x>62</x>
<y>140</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Left Side</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb4">
<property name="geometry">
<rect>
<x>84</x>
<y>140</y>
<width>17</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Center</string>
</property>
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb5">
<property name="geometry">
<rect>
<x>107</x>
<y>140</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Right Side</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb2">
<property name="geometry">
<rect>
<x>107</x>
<y>159</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Right Front</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb6">
<property name="geometry">
<rect>
<x>62</x>
<y>121</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Left Rear</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb1">
<property name="geometry">
<rect>
<x>84</x>
<y>159</y>
<width>17</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Front</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</widget>
以块的形式添加整个FileNamingWidget.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Filename_Folder_Widget</class>
<widget class="QTabWidget" name="Filename_Folder_Widget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>261</width>
<height>550</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>260</width>
<height>550</height>
</size>
</property>
<property name="windowTitle">
<string>TabWidget</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="FileNamingTab">
<attribute name="title">
<string>File Naming</string>
</attribute>
<widget class="QLabel" name="AspectLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<width>47</width>
<height>13</height>
</rect>
</property>
<property name="text">
<string>Aspect</string>
</property>
</widget>
<widget class="QLabel" name="SubjectLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>47</width>
<height>21</height>
</rect>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Subject</string>
</property>
</widget>
<widget class="QLabel" name="RangeLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>47</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Range</string>
</property>
</widget>
<widget class="QLabel" name="PositionLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>90</y>
<width>47</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Position</string>
</property>
</widget>
<widget class="QComboBox" name="SubjectDropDown">
<property name="geometry">
<rect>
<x>60</x>
<y>30</y>
<width>91</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QComboBox" name="RangeDropDown">
<property name="geometry">
<rect>
<x>60</x>
<y>60</y>
<width>91</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QComboBox" name="PositionDropDown">
<property name="geometry">
<rect>
<x>60</x>
<y>90</y>
<width>91</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="FOVLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>190</y>
<width>47</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>FOV</string>
</property>
</widget>
<widget class="QComboBox" name="FOVDropDown">
<property name="geometry">
<rect>
<x>60</x>
<y>190</y>
<width>91</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="EditOptionsButton">
<property name="geometry">
<rect>
<x>20</x>
<y>310</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Edit I/O Settings</string>
</property>
</widget>
<widget class="QLabel" name="RunLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>220</y>
<width>47</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Run #</string>
</property>
</widget>
<widget class="QLabel" name="TakeLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>250</y>
<width>47</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Take #</string>
</property>
</widget>
<widget class="Line" name="HorizLine1">
<property name="geometry">
<rect>
<x>10</x>
<y>300</y>
<width>221</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
<widget class="QPushButton" name="LoadButton">
<property name="geometry">
<rect>
<x>60</x>
<y>340</y>
<width>51</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Load</string>
</property>
</widget>
<widget class="QPushButton" name="SaveButton">
<property name="geometry">
<rect>
<x>120</x>
<y>340</y>
<width>51</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Save</string>
</property>
</widget>
<widget class="QPushButton" name="SettingsButton">
<property name="geometry">
<rect>
<x>120</x>
<y>310</y>
<width>101</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Structure Settings</string>
</property>
</widget>
<widget class="QTextEdit" name="NotesInput">
<property name="geometry">
<rect>
<x>10</x>
<y>390</y>
<width>221</width>
<height>111</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="NotesLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>370</y>
<width>211</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Notes</string>
</property>
</widget>
<widget class="QPushButton" name="SaveNotesButton">
<property name="geometry">
<rect>
<x>70</x>
<y>500</y>
<width>81</width>
<height>23</height>
</rect>
</property>
<property name="text">
<string>Save Notes</string>
</property>
</widget>
<widget class="QTextEdit" name="AspectPreview">
<property name="geometry">
<rect>
<x>170</x>
<y>140</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" name="SubjectPreview">
<property name="geometry">
<rect>
<x>160</x>
<y>30</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" name="RangePreview">
<property name="geometry">
<rect>
<x>160</x>
<y>60</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" name="PositionPreview">
<property name="geometry">
<rect>
<x>160</x>
<y>90</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" name="FOVPreview">
<property name="geometry">
<rect>
<x>160</x>
<y>190</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" name="RunPreview">
<property name="geometry">
<rect>
<x>160</x>
<y>220</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QTextEdit" name="SuffixInput">
<property name="geometry">
<rect>
<x>60</x>
<y>280</y>
<width>171</width>
<height>21</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
</widget>
<widget class="QLabel" name="SuffixLabel_2">
<property name="geometry">
<rect>
<x>10</x>
<y>280</y>
<width>47</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Suffix</string>
</property>
</widget>
<widget class="QTextEdit" name="TakePreview">
<property name="geometry">
<rect>
<x>160</x>
<y>250</y>
<width>71</width>
<height>21</height>
</rect>
</property>
<property name="verticalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QSpinBox" name="RunSpin">
<property name="geometry">
<rect>
<x>60</x>
<y>220</y>
<width>91</width>
<height>22</height>
</rect>
</property>
<property name="frame">
<bool>true</bool>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
<widget class="QSpinBox" name="TakeSpin">
<property name="geometry">
<rect>
<x>60</x>
<y>250</y>
<width>91</width>
<height>22</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="SubjectLabel_2">
<property name="geometry">
<rect>
<x>166</x>
<y>0</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Output</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="SubjectLabel_3">
<property name="geometry">
<rect>
<x>60</x>
<y>0</y>
<width>91</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Input</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QLabel" name="SubjectLabel_4">
<property name="geometry">
<rect>
<x>10</x>
<y>0</y>
<width>31</width>
<height>21</height>
</rect>
</property>
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Field</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="Line" name="HorizLine1_2">
<property name="geometry">
<rect>
<x>10</x>
<y>360</y>
<width>221</width>
<height>16</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
带单选按钮的块:
<widget class="QRadioButton" name="Rb8">
<property name="geometry">
<rect>
<x>107</x>
<y>121</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Right Rear</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb0">
<property name="enabled">
<bool>true</bool>
</property>
<property name="geometry">
<rect>
<x>62</x>
<y>159</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Left Front</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb9">
<property name="geometry">
<rect>
<x>130</x>
<y>140</y>
<width>13</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Multi Aspect</string>
</property>
<property name="text">
<string/>
</property>
<property name="shortcut">
<string/>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb7">
<property name="geometry">
<rect>
<x>84</x>
<y>121</y>
<width>17</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Rear</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb3">
<property name="geometry">
<rect>
<x>62</x>
<y>140</y>
<width>16</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Left Side</string>
</property>
<property name="text">
<string/>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
<widget class="QRadioButton" name="Rb4">
<property name="geometry">
<rect>
<x>84</x>
<y>140</y>
<width>17</width>
<height>13</height>
</rect>
</property>
<property name="toolTip">
<string>Center</string>
</property>
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="autoExclusive">
<bool>false</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
(插入整个uifile太麻烦了)