我面临我的QTableView问题,因为在用变量填充它后,它阻止了其他Ui元素。这是我的预期UI设计
表视图被填充后(带有测试变量)的作用
在Designer应用程序中设置ui时,我会错过什么吗?抱歉,新手问题是我第一次处理tableview。
用于填充表格的代码:
def createTable(self):
# Create table
header_labels = ['Username', 'Password', 'Account Type']
profiles = [["test", "pokemon","nanana"], ["dreams", "nani","hikari"]]
self.tableWidget = QTableWidget()
self.tableWidget.setRowCount(len(profiles))
self.tableWidget.setColumnCount(len(header_labels))
self.tableWidget.setHorizontalHeaderLabels(header_labels)
self.tableWidget.verticalHeader().setVisible(False)
for i,profile in enumerate(profiles):
self.tableWidget.setItem(i, 0, QTableWidgetItem(profile[0]))
self.tableWidget.setItem(i, 1, QTableWidgetItem(profile[1]))
self.tableWidget.setItem(i, 2, QTableWidgetItem(profile[2]))
self.tableWidget.move(0, 0)
我的Ui码(如果需要参考)
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>618</width>
<height>463</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>20</x>
<y>20</y>
<width>161</width>
<height>16</height>
</rect>
</property>
<property name="font">
<font>
<family>Arial</family>
<pointsize>12</pointsize>
</font>
</property>
<property name="text">
<string>Account Management</string>
</property>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>20</x>
<y>50</y>
<width>301</width>
<height>194</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetFixedSize</enum>
</property>
<item>
<widget class="QTableView" name="profileView">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContents</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>430</x>
<y>300</y>
<width>158</width>
<height>112</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addProfileButton">
<property name="text">
<string>Add Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteProfileButton">
<property name="text">
<string>Delete Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="updateProfileButton">
<property name="text">
<string>Update Profile</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_3">
<property name="text">
<string>Logout</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>
不确定QtDesigner是否没有创建固定的宽度和高度,但是使用.setFixedWidth()
和.setFixedHeight()
起作用。