[PyQt] TableWidget: stretch factor
Rich Shepard
rshepard at appl-ecosys.com
Fri Jan 13 16:01:09 GMT 2017
I've read that a widget should have a stretch factor which, for a table
widget, should allow me to set relative sizes for each column. I'm not
finding this stretch factor in the Property Editor.
The section in which I thought I'd find this adjustment, QTableWidget,
does not appear to have this. I do see a a Horizontal Stretch under Size
Policy, but that has only a single value.
Please point out what I've done incorrectly. The .ui file is attached and
the last three tabs each have a table widget. I'd like to expand the
right-most column to fill the empty area.
Rich
-------------- next part --------------
<?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>800</width>
<height>600</height>
</rect>
</property>
<property name="windowTitle">
<string>CRM-0.1</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QTabWidget" name="maintab">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>763</width>
<height>511</height>
</rect>
</property>
<property name="currentIndex">
<number>2</number>
</property>
<widget class="QWidget" name="contacts">
<attribute name="title">
<string>Contacts</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>311</width>
<height>161</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lastNameLabel">
<property name="text">
<string>Last name:</string>
</property>
<property name="buddy">
<cstring>lastName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="lastName">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="titleLabel_2">
<property name="text">
<string>Title:</string>
</property>
<property name="buddy">
<cstring>titleLineEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="titleLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="officePhoneLabel">
<property name="text">
<string>Office:</string>
</property>
<property name="buddy">
<cstring>officePhoneLineEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="officePhoneLineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="mobilePhoneLabel">
<property name="text">
<string>Mobile:</string>
</property>
<property name="buddy">
<cstring>mobiePhoneLineEdit</cstring>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="mobiePhoneLineEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="emailLabel">
<property name="text">
<string>E-mail:</string>
</property>
<property name="buddy">
<cstring>emailLineEdit</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="emailLineEdit"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>350</x>
<y>10</y>
<width>341</width>
<height>161</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="firstNameLabel">
<property name="text">
<string>First name:</string>
</property>
<property name="buddy">
<cstring>firstNameLineEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="firstNameLineEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="companyLabel">
<property name="text">
<string>Company:</string>
</property>
<property name="buddy">
<cstring>companyLineEdit</cstring>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="companyLineEdit"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="phoneExtLabel">
<property name="text">
<string>Ext.:</string>
</property>
<property name="buddy">
<cstring>extensionlineEdit</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QLineEdit" name="extensionlineEdit"/>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="faxLineEdit"/>
</item>
<item row="4" column="0">
<widget class="QLabel" name="mainPhoneLabel">
<property name="text">
<string>Main:</string>
</property>
<property name="buddy">
<cstring>mainPhonelineEdit</cstring>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="mainPhonelineEdit"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="faxLabel">
<property name="text">
<string>Fax:</string>
</property>
<property name="buddy">
<cstring>faxLineEdit</cstring>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>240</y>
<width>681</width>
<height>194</height>
</rect>
</property>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="commentLabel">
<property name="text">
<string>Comments</string>
</property>
<property name="buddy">
<cstring>commentTextEdit</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPlainTextEdit" name="commentTextEdit"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="horizontalLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>10</y>
<width>711</width>
<height>171</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4"/>
</widget>
<widget class="QWidget" name="verticalLayoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>711</width>
<height>441</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout"/>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>40</x>
<y>440</y>
<width>254</width>
<height>24</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>&Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="text">
<string>&Modify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton">
<property name="text">
<string>&Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="companies">
<attribute name="title">
<string>Companies</string>
</attribute>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>30</x>
<y>320</y>
<width>254</width>
<height>24</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="addButton_2">
<property name="text">
<string>&Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton_3">
<property name="text">
<string>&Edit</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton_2">
<property name="text">
<string>&Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>1</y>
<width>762</width>
<height>282</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="industryLabel">
<property name="text">
<string>Industry</string>
</property>
<property name="buddy">
<cstring>industry</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="industry"/>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>198</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="statusLabel">
<property name="text">
<string>Status</string>
</property>
<property name="buddy">
<cstring>status</cstring>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="status"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="nameLabel">
<property name="text">
<string>Name</string>
</property>
<property name="buddy">
<cstring>companyName</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="companyName"/>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="addr1Label">
<property name="text">
<string>Address 1</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="addr1"/>
</item>
</layout>
</item>
<item>
<layout class="QFormLayout" name="formLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="addr2Label">
<property name="text">
<string>Address 2</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="addr2"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="cityLabel">
<property name="text">
<string>City</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="city"/>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>36</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="stateLabel">
<property name="text">
<string>State</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="state"/>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="postcodeLabel">
<property name="text">
<string>Post Code</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="postcode"/>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>28</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="countryLabel">
<property name="text">
<string>Country</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="country"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="phoneLabel">
<property name="text">
<string>Phone</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="phoneNbr"/>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="urlLabel">
<property name="text">
<string>URL</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="url"/>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="activities">
<attribute name="title">
<string>Activities</string>
</attribute>
<widget class="QWidget" name="layoutWidget_3">
<property name="geometry">
<rect>
<x>50</x>
<y>440</y>
<width>254</width>
<height>24</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QPushButton" name="addButton_3">
<property name="text">
<string>&Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton_2">
<property name="text">
<string>&Modify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton_3">
<property name="text">
<string>&Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>711</width>
<height>421</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<widget class="QLabel" name="nameLabel_2">
<property name="text">
<string>Name</string>
</property>
<property name="buddy">
<cstring>name</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="name"/>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="companyLabel_2">
<property name="text">
<string>Company</string>
</property>
<property name="buddy">
<cstring>company</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="company"/>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="rowCount">
<number>15</number>
</property>
<property name="columnCount">
<number>5</number>
</property>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<column>
<property name="text">
<string>Date</string>
</property>
</column>
<column>
<property name="text">
<string>Type</string>
</property>
</column>
<column>
<property name="text">
<string>Next Contact</string>
</property>
</column>
<column>
<property name="text">
<string>Actions</string>
</property>
</column>
<column>
<property name="text">
<string>Comment</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="cases">
<attribute name="title">
<string>Cases</string>
</attribute>
<widget class="QWidget" name="layoutWidget_4">
<property name="geometry">
<rect>
<x>60</x>
<y>440</y>
<width>254</width>
<height>24</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_8">
<item>
<widget class="QPushButton" name="addButton_4">
<property name="text">
<string>&Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton_4">
<property name="text">
<string>&Modify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton_4">
<property name="text">
<string>&Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>711</width>
<height>431</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_5">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QLabel" name="nameLabel_3">
<property name="text">
<string>Name</string>
</property>
<property name="buddy">
<cstring>name</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="name_2"/>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="companyLabel_3">
<property name="text">
<string>Company</string>
</property>
<property name="buddy">
<cstring>company</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="company_3"/>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableWidget_2">
<property name="rowCount">
<number>15</number>
</property>
<property name="columnCount">
<number>5</number>
</property>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>Start Date</string>
</property>
</column>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>Request</string>
</property>
</column>
<column>
<property name="text">
<string>Request</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="QWidget" name="projects">
<attribute name="title">
<string>Projects</string>
</attribute>
<widget class="QWidget" name="layoutWidget_5">
<property name="geometry">
<rect>
<x>30</x>
<y>440</y>
<width>254</width>
<height>24</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_9">
<item>
<widget class="QPushButton" name="addButton_5">
<property name="text">
<string>&Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="editButton_5">
<property name="text">
<string>&Modify</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="deleteButton_5">
<property name="text">
<string>&Delete</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>721</width>
<height>431</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_12">
<item>
<widget class="QLabel" name="nameLabel_4">
<property name="text">
<string>Name</string>
</property>
<property name="buddy">
<cstring>name</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="name_3"/>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="companyLabel_4">
<property name="text">
<string>Company</string>
</property>
<property name="buddy">
<cstring>company</cstring>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="company_2"/>
</item>
</layout>
</item>
<item>
<widget class="QTableWidget" name="tableWidget_3">
<property name="rowCount">
<number>15</number>
</property>
<property name="columnCount">
<number>3</number>
</property>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<row/>
<column>
<property name="text">
<string>New Column</string>
</property>
</column>
<column>
<property name="text">
<string>Number</string>
</property>
</column>
<column>
<property name="text">
<string>Description</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="geometry">
<rect>
<x>490</x>
<y>520</y>
<width>181</width>
<height>32</height>
</rect>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<zorder>buttonBox</zorder>
<zorder>maintab</zorder>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>19</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>File</string>
</property>
<addaction name="actionNew"/>
<addaction name="actionOpen"/>
<addaction name="actionSave"/>
<addaction name="actionSave_as"/>
<addaction name="actionImport"/>
<addaction name="actionExport"/>
</widget>
<widget class="QMenu" name="menuEdit">
<property name="title">
<string>Edit</string>
</property>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
</widget>
<widget class="QMenu" name="menuReports">
<property name="title">
<string>Reports</string>
</property>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
<addaction name="menuReports"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionNew">
<property name="text">
<string>New</string>
</property>
</action>
<action name="actionOpen">
<property name="text">
<string>Open</string>
</property>
</action>
<action name="actionSave">
<property name="text">
<string>Save</string>
</property>
</action>
<action name="actionSave_as">
<property name="text">
<string>Save as</string>
</property>
</action>
<action name="actionImport">
<property name="text">
<string>Import</string>
</property>
</action>
<action name="actionExport">
<property name="text">
<string>Export</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>
More information about the PyQt
mailing list