本文整理汇总了Python中PyQt5.QtWidgets.QStyledItemDelegate.sizeHint方法的典型用法代码示例。如果您正苦于以下问题:Python QStyledItemDelegate.sizeHint方法的具体用法?Python QStyledItemDelegate.sizeHint怎么用?Python QStyledItemDelegate.sizeHint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QStyledItemDelegate
的用法示例。
在下文中一共展示了QStyledItemDelegate.sizeHint方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sizeHint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import sizeHint [as 别名]
def sizeHint(self, option, index):
s = QStyledItemDelegate.sizeHint(self, option, index)
if s.width() > 150:
s.setWidth(150)
elif s.width() < 50:
s.setWidth(50)
return s + QSize(18, 0)
示例2: sizeHint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import sizeHint [as 别名]
def sizeHint(self, option, index):
layer = index.data()
if isinstance(layer, Layer):
self._w.layer = layer
self._w.channelSelector.setVisible(True)
return self._w.sizeHint()
else:
return QStyledItemDelegate.sizeHint(self, option, index)
示例3: sizeHint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import sizeHint [as 别名]
def sizeHint(self, option, index):
fm = option.fontMetrics
if index.column() == residNum:
return QSize(fm.width("9,999,999"), fm.height())
if index.column() == residName:
text = index.model().data(index)
document = QTextDocument()
document.setDefaultFont(option.font)
document.setHtml(text)
return QSize(document.idealWidth() + 5, fm.height())
return QStyledItemDelegate.sizeHint(self, option, index)
示例4: sizeHint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import sizeHint [as 别名]
def sizeHint(self, option, index):
"""QStyledItemDelegate.sizeHint implementation
"""
options = QStyleOptionViewItem(option)
self.initStyleOption(options,index)
doc = QTextDocument()
doc.setDocumentMargin(1)
# bad long (multiline) strings processing doc.setTextWidth(options.rect.width())
doc.setHtml(options.text)
return QSize(doc.idealWidth(),
QStyledItemDelegate.sizeHint(self, option, index).height())
示例5: sizeHint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import sizeHint [as 别名]
def sizeHint(self, option, index):
# s = QStyledItemDelegate.sizeHint(self, option, index)
item = QModelIndex()
for i in range(self.mdlPersos.rowCount()):
if self.mdlPersos.ID(i) == index.data():
item = self.mdlPersos.index(i, Perso.name.value)
opt = QStyleOptionViewItem(option)
self.initStyleOption(opt, item)
s = QStyledItemDelegate.sizeHint(self, opt, item)
if s.width() > 200:
s.setWidth(200)
elif s.width() < 100:
s.setWidth(100)
return s + QSize(18, 0)
示例6: sizeHint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import sizeHint [as 别名]
def sizeHint(self, option, index):
"""Returns a QSize bounding box of the area required to paint the data in the model at the index.
Returns the size of the bounding box of the area required to paint the data in the model
at the specified index. This is the sum of decoration pixmap widths, and the sizeHint provided
by the custom value_painter if it exists.
Args:
option - QStyleOptionViewItem
index - QModelIndex
Returns:
A QSize bounding box of the size required to paint the value of the data in the model plus
decorations.
"""
value_painter = self._get_value_painter(index)
if value_painter is None:
return QStyledItemDelegate.sizeHint(self, option, index)
decs = self._get_decorations(index, bool(option.state & QStyle.State_Selected))
pix_widths = [dec.pixmap.width() for dec in decs]
size = value_painter.sizeHint(option, index)
size.setWidth(size.width() + sum(pix_widths))
return size
示例7: sizeHint
# 需要导入模块: from PyQt5.QtWidgets import QStyledItemDelegate [as 别名]
# 或者: from PyQt5.QtWidgets.QStyledItemDelegate import sizeHint [as 别名]
def sizeHint(self, option, index):
s = QStyledItemDelegate.sizeHint(self, option, index)
if s.width() < 200:
s.setWidth(200)
return s