本文整理汇总了Python中PySide.QtGui.QTableView.setSizePolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QTableView.setSizePolicy方法的具体用法?Python QTableView.setSizePolicy怎么用?Python QTableView.setSizePolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PySide.QtGui.QTableView
的用法示例。
在下文中一共展示了QTableView.setSizePolicy方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LimitWizardPage
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSizePolicy [as 别名]
#.........这里部分代码省略.........
def createEditor(self, parent, option, index):
return None
def setEditorData(self, editor, index):
pass
def setModelData(self, editor, model, index):
return None
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle('Limit')
def _initUI(self):
# Variables
self._widgets = {}
tbl_model = self._LimitTableModel()
# Widgets
self._cb_limit = QComboBox()
self._cb_limit.setModel(self._LimitComboBoxModel())
btn_limit_add = QPushButton()
btn_limit_add.setIcon(getIcon("list-add"))
self._tbl_limit = QTableView()
self._tbl_limit.setModel(tbl_model)
self._tbl_limit.setItemDelegate(self._LimitTableDelegate())
header = self._tbl_limit.horizontalHeader()
header.setResizeMode(QHeaderView.Stretch)
header.hide()
policy = self._tbl_limit.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_limit.setSizePolicy(policy)
tlb_limit = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
tlb_limit.addWidget(spacer)
act_remove = tlb_limit.addAction(getIcon("list-remove"), "Remove limit")
act_clear = tlb_limit.addAction(getIcon("edit-clear"), "Clear")
# Layouts
layout = _ExpandableOptionsWizardPage._initUI(self)
sublayout = QHBoxLayout()
sublayout.addWidget(self._cb_limit, 1)
sublayout.addWidget(btn_limit_add)
layout.addRow("Select", sublayout)
layout.addRow(self._tbl_limit)
layout.addRow(tlb_limit)
# Signals
btn_limit_add.released.connect(self._onLimitAdd)
act_remove.triggered.connect(self._onLimitRemove)
act_clear.triggered.connect(self._onLimitClear)
self._tbl_limit.doubleClicked.connect(self._onLimitDoubleClicked)
tbl_model.dataChanged.connect(self.valueChanged)
tbl_model.rowsInserted.connect(self.valueChanged)
tbl_model.rowsRemoved.connect(self.valueChanged)
return layout
示例2: DetectorWizardPage
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSizePolicy [as 别名]
#.........这里部分代码省略.........
key = index.model().data(index, Qt.DisplayRole)
editor.setText(key)
def setModelData(self, editor, model, index):
column = index.column()
if column == 0:
if not editor.hasAcceptableInput():
return
model.setData(index, editor.text())
def __init__(self, options, parent=None):
_ExpandableOptionsWizardPage.__init__(self, options, parent)
self.setTitle('Detector')
def _initUI(self):
# Variables
self._widgets = {}
tbl_model = self._DetectorTableModel()
# Widgets
self._cb_detector = QComboBox()
self._cb_detector.setModel(self._DetectorComboBoxModel())
btn_detector_add = QPushButton()
btn_detector_add.setIcon(getIcon("list-add"))
self._tbl_detector = QTableView()
self._tbl_detector.setModel(tbl_model)
self._tbl_detector.setItemDelegate(self._DetectorTableDelegate())
header = self._tbl_detector.horizontalHeader()
header.setResizeMode(1, QHeaderView.Stretch)
policy = self._tbl_detector.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_detector.setSizePolicy(policy)
tlb_detector = QToolBar()
spacer = QWidget()
spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
tlb_detector.addWidget(spacer)
act_remove = tlb_detector.addAction(getIcon("list-remove"), "Remove detector")
act_clear = tlb_detector.addAction(getIcon("edit-clear"), "Clear")
# Layouts
layout = _ExpandableOptionsWizardPage._initUI(self)
sublayout = QHBoxLayout()
sublayout.addWidget(self._cb_detector, 1)
sublayout.addWidget(btn_detector_add)
layout.addRow("Select", sublayout)
layout.addRow(self._tbl_detector)
layout.addRow(tlb_detector)
# Signals
btn_detector_add.released.connect(self._onDetectorAdd)
act_remove.triggered.connect(self._onDetectorRemove)
act_clear.triggered.connect(self._onDetectorClear)
self._tbl_detector.doubleClicked.connect(self._onDetectorDoubleClicked)
tbl_model.dataChanged.connect(self.valueChanged)
tbl_model.rowsInserted.connect(self.valueChanged)
tbl_model.rowsRemoved.connect(self.valueChanged)
return layout
示例3: ModelTableWidget
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSizePolicy [as 别名]
#.........这里部分代码省略.........
return False
row = index.row()
self._models[row] = value
self.dataChanged.emit(index, index)
return True
def insertRows(self, row, count=1, parent=None):
if parent is None:
parent = QModelIndex()
self.beginInsertRows(parent, row, row + count - 1)
for _ in range(count):
self._models.insert(row, None)
self.endInsertRows()
return True
def removeRows(self, row, count=1, parent=None):
if parent is None:
parent = QModelIndex()
self.beginRemoveRows(parent, row, row + count - 1)
for index in reversed(range(row, row + count)):
self._models.pop(index)
self.endRemoveRows()
return True
def append(self, model):
self.insert(self.rowCount(), model)
def insert(self, index, model):
self.insertRows(index)
self.setData(self.createIndex(index, 0), model)
def remove(self, model):
index = self._models.index(model)
self.removeRows(index)
def clear(self):
self.removeRows(0, self.rowCount())
def models(self):
models = set(self._models)
models.discard(None)
return models
def model(self, index):
return self._models[index.row()]
def __init__(self, parent=None):
QWidget.__init__(self, parent)
# Variables
model = self._ModelTableModel()
# Widgets
self._tbl_models = QTableView()
self._tbl_models.setModel(model)
header = self._tbl_models.horizontalHeader()
header.setResizeMode(QHeaderView.Stretch)
policy = self._tbl_models.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_models.setSizePolicy(policy)
self._tbl_models.setSelectionMode(QTableView.SelectionMode.MultiSelection)
# Layouts
layout = QVBoxLayout()
layout.addWidget(self._tbl_models)
self.setLayout(layout)
# Signals
model.dataChanged.connect(self.dataChanged)
def addModel(self, model):
self._tbl_models.model().append(model)
def addModels(self, models):
for model in models:
self.addModel(model)
def removeModel(self, model):
self._tbl_models.model().remove(model)
def clear(self):
self._tbl_models.model().clear()
def models(self):
return self._tbl_models.model().models()
def currentModels(self):
tbl_model = self._tbl_models.model()
models = []
for index in self._tbl_models.selectionModel().selection().indexes():
models.append(tbl_model.model(index))
return models
示例4: WarningWizardPage
# 需要导入模块: from PySide.QtGui import QTableView [as 别名]
# 或者: from PySide.QtGui.QTableView import setSizePolicy [as 别名]
class WarningWizardPage(_OptionsWizardPage):
class _WarningTableModel(QAbstractTableModel):
def __init__(self, warns=None):
QAbstractTableModel.__init__(self)
if warns is None:
warns = []
self._warns = warns
def rowCount(self, *args, **kwargs):
return len(self._warns)
def columnCount(self, *args, **kwargs):
return 2
def data(self, index, role=Qt.DisplayRole):
if not index.isValid() or \
not (0 <= index.row() < len(self._warns)):
return None
if role == Qt.TextAlignmentRole:
return Qt.AlignCenter
if role != Qt.DisplayRole:
return None
return str(self._warns[index.row()][index.column()])
def headerData(self, section , orientation, role):
if role != Qt.DisplayRole:
return None
if orientation == Qt.Horizontal:
if section == 0:
return 'Program'
elif section == 1:
return 'Warning'
elif orientation == Qt.Vertical:
return str(section + 1)
def flags(self, index):
if not index.isValid():
return Qt.ItemIsEnabled
return Qt.ItemFlags(QAbstractTableModel.flags(self, index))
def __init__(self, options, parent=None):
_OptionsWizardPage.__init__(self, options, parent=parent)
self.setTitle("Conversion warnings")
# Widgets
self._lbl_count = SimulationCountLabel()
self._lbl_count.setAlignment(Qt.AlignCenter)
# Layouts
layout = self.layout()
frm_line = QFrame()
frm_line.setFrameStyle(QFrame.HLine)
frm_line.setFrameShadow(QFrame.Sunken)
layout.addWidget(frm_line)
sublayout = QHBoxLayout()
sublayout.setContentsMargins(10, 0, 10, 0)
sublayout.addWidget(self._lbl_count)
layout.addLayout(sublayout)
def _initUI(self):
# Widgets
self._tbl_warnings = QTableView()
self._tbl_warnings.setModel(self._WarningTableModel())
header = self._tbl_warnings.horizontalHeader()
header.setResizeMode(1, QHeaderView.Stretch)
policy = self._tbl_warnings.sizePolicy()
policy.setVerticalStretch(True)
self._tbl_warnings.setSizePolicy(policy)
# Layouts
layout = _OptionsWizardPage._initUI(self)
layout.addRow(self._tbl_warnings)
return layout
def initializePage(self):
count = 0
warns = []
for program in self.options().programs:
converter = program.converter_class()
warnings.simplefilter("always")
with warnings.catch_warnings(record=True) as ws:
list_options = converter.convert(self.options())
count += len(list_options)
for w in ws:
warns.append((program, w.message))
model = self._WarningTableModel(warns)
self._tbl_warnings.setModel(model)
#.........这里部分代码省略.........