当前位置: 首页>>代码示例>>Python>>正文


Python QTextDocument.idealWidth方法代码示例

本文整理汇总了Python中PyQt4.QtGui.QTextDocument.idealWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QTextDocument.idealWidth方法的具体用法?Python QTextDocument.idealWidth怎么用?Python QTextDocument.idealWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtGui.QTextDocument的用法示例。


在下文中一共展示了QTextDocument.idealWidth方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
 def sizeHint(self, option, index):
     text = index.model().data(index).toString()
     document = QTextDocument()
     document.setDefaultFont(option.font)
     document.setHtml(text)
     return QSize(document.idealWidth() + 5,
                  option.fontMetrics.height())
开发者ID:DaoQiu,项目名称:VimProject,代码行数:9,代码来源:genericdelegates.py

示例2: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
	def sizeHint(self, option, index):
		options = QStyleOptionViewItemV4(option)
		self.initStyleOption(options,index)

		doc = QTextDocument()
		doc.setHtml(options.text)
		doc.setTextWidth(options.rect.width())
		return QtCore.QSize(doc.idealWidth(), doc.size().height())
开发者ID:tommo,项目名称:gii,代码行数:10,代码来源:HTMLItemDelegate.py

示例3: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
    def sizeHint(self, option, index):
        optionV4 = QStyleOptionViewItemV4(option)
        self.initStyleOption(optionV4, index)

        doc = QTextDocument()
        doc.setHtml(optionV4.text)
        doc.setTextWidth(optionV4.rect.width())

        return QSize(doc.idealWidth(), max(doc.size().height(), optionV4.decorationSize.height()))
开发者ID:frankrousseau,项目名称:weboob,代码行数:11,代码来源:qt.py

示例4: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
    def sizeHint(self, option, index):
        """Calculate the needed size."""
        options = QStyleOptionViewItemV4(option)
        self.initStyleOption(options, index)

        doc = QTextDocument()
        doc.setHtml(options.text)
        doc.setTextWidth(options.rect.width())
        return QSize(doc.idealWidth(), doc.size().height())
开发者ID:Nicogue,项目名称:Encuentro,代码行数:11,代码来源:central_panel.py

示例5: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
	def sizeHint(self, option, index):
		fm = option.fontMetrics
		if index.column() in (SRC_ADDR, DST_ADDR):
			text = index.model().data(index).toString()
			document = QTextDocument()
			document.setDefaultFont(option.font)
			document.setHtml(text)
			#document.setPageSize(option.rect.size())
			return QSize(document.idealWidth() + 5, 1.3 * fm.height())
		return QItemDelegate.sizeHint(self, option, index)
开发者ID:grucha,项目名称:Sniffer,代码行数:12,代码来源:packets.py

示例6: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
 def sizeHint(self, option, index):
     fm = option.fontMetrics
     if index.column() == TEU:
         return QSize(fm.width("9,999,999"), fm.height())
     if index.column() == DESCRIPTION:
         text = index.model().data(index).toString()
         document = QTextDocument()
         document.setDefaultFont(option.font)
         document.setHtml(text)
         return QSize(document.idealWidth() + 5, fm.height())
     return QStyledItemDelegate.sizeHint(self, option, index)
开发者ID:DaoQiu,项目名称:VimProject,代码行数:13,代码来源:ships_ans.py

示例7: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
    def sizeHint(self, option, index):
        """QStyledItemDelegate.sizeHint implementation
        """
        options = QStyleOptionViewItemV4(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(), doc.size().height())
开发者ID:cmpitg,项目名称:qutepart,代码行数:13,代码来源:htmldelegate.py

示例8: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
	def sizeHint(self, option, index):
		"""
		Reimplements the :meth:`QStyledItemDelegate.sizeHint` method.
		"""

		document = QTextDocument()
		document.setDefaultFont(option.font)
		data = index.model().data(index)
		text = umbra.ui.common.getQVariantAsString(data)
		self.__label.setText(text)
		document.setHtml(text)
		return QSize(document.idealWidth() + self.__indent, option.fontMetrics.height())
开发者ID:KelSolaar,项目名称:Umbra,代码行数:14,代码来源:delegates.py

示例9: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
 def sizeHint( self, option, index ):
     fm = option.fontMetrics
     if index.column() in ( NOMBRE, TELEFONO, RUC, EMAIL ):
         text = index.model().data( index ).toString()
         document = QTextDocument()
         document.setDefaultFont( option.font )
         document.setHtml( text )
         return QSize( document.idealWidth() + 5, fm.height() )
     elif index.column() == ACTIVO:
             return QSize( fm.width( "9" ), fm.height() )
     else:
         return QStyledItemDelegate.sizeHint( self, option, index )
开发者ID:armonge,项目名称:EsquipulasPy,代码行数:14,代码来源:catalogos.py

示例10: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
 def sizeHint(self, option, index):
     """
     This method is re-implemented because Description column is using HTML, it must return the exactly number of characters for
     presentation purpose rather than the number of HTML raw characters.
     """
     fm = option.fontMetrics
     if index.column() == TEU:
         return QSize(fm.width("9,999,999"), fm.height())
     if index.column() == DESCRIPTION:
         text = index.model().data(index).toString()
         document = QTextDocument()
         document.setDefaultFont(option.font)
         document.setHtml(text)
         return QSize(document.idealWidth() + 5, fm.height())
     return QStyledItemDelegate.sizeHint(self, option, index)
开发者ID:DaoQiu,项目名称:VimProject,代码行数:17,代码来源:ships.py

示例11: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
 def sizeHint(self, option1, index):
     # option.rect is a zero rect
     width = self.parent().columnWidth(index.column())
     
     if index.data(Qt.DisplayRole).type() == QMetaType.Double:
         return QSize(width, 18)
     
     option = QStyleOptionViewItemV4(option1)
     self.initStyleOption(option, index)
     
     if not option.text:
         iconSize = option.icon.actualSize(QSize(32, 32))
         return QSize(32, max(32, iconSize.height() + 4))
     
     doc = QTextDocument()
     doc.setHtml(option.text)
     doc.setTextWidth(self._preferredMessageWidth(width))
     
     return QSize(doc.idealWidth(), max(32, doc.size().height() + 4))
开发者ID:hannesrauhe,项目名称:lunchinator,代码行数:21,代码来源:message_item_delegate.py

示例12: paint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
    def paint(self, painter, option, index):
        painter.save()

        cell_width = self.size.width()

        #if option.state & QStyle.State_Selected:
        #    painter.fillRect(option.rect, option.palette.highlight())
        #painter.drawRect(option.rect)


        # Draw marks before translating painter
        # =====================================

        # Draw avatar
        if not self.avatar:
            avatar_filepath = index.data(self.AvatarRole).toPyObject()
            self.avatar = QPixmap(avatar_filepath)
        x = option.rect.left() + (self.BOX_MARGIN * 2)
        y = option.rect.top() + (self.BOX_MARGIN * 2)
        rect = QRect(x, y, self.AVATAR_SIZE, self.AVATAR_SIZE)
        painter.drawPixmap(rect, self.avatar)

        # Draw verified account icon
        if index.data(self.VerifiedRole).toPyObject():
            rect2 = QRect(rect.right() - 11, rect.bottom() - 10, 16, 16)
            painter.drawPixmap(rect2, self.verified_icon)

        marks_margin = 0
        # Favorite mark
        if index.data(self.FavoritedRole).toPyObject():
            x = cell_width - 16 - self.BOX_MARGIN
            y = option.rect.top() + self.BOX_MARGIN
            rect = QRect(x, y, 16, 16)
            painter.drawPixmap(rect, self.favorite_icon)
            marks_margin = 16

        # Draw reposted icon
        if index.data(self.RepeatedRole).toPyObject():
            x = cell_width - 16 - self.BOX_MARGIN - marks_margin
            y = option.rect.top() + self.BOX_MARGIN
            rect = QRect(x, y, 16, 16)
            painter.drawPixmap(rect, self.repeated_icon)

        # Draw protected account icon
        protected_icon_margin = 0
        if index.data(self.ProtectedRole).toPyObject():
            x = option.rect.left() + self.BOX_MARGIN + self.AVATAR_SIZE + self.LEFT_MESSAGE_MARGIN
            y = option.rect.top() + self.BOX_MARGIN
            rect = QRect(x, y, 16, 16)
            painter.drawPixmap(rect, self.protected_icon)
            protected_icon_margin = 16

        # ==== End of pixmap drawing ====

        accumulated_height = 0

        # Draw fullname
        fullname = self.__render_fullname(cell_width, index)
        x = option.rect.left() + self.BOX_MARGIN + self.AVATAR_SIZE
        x += self.LEFT_MESSAGE_MARGIN + protected_icon_margin
        y = option.rect.top()
        painter.translate(x, y)
        fullname.drawContents(painter)

        # Draw username
        username = self.__render_username(cell_width, index)
        painter.translate(fullname.idealWidth(), 0)
        username.drawContents(painter)

        # Draw status message
        x = -fullname.idealWidth() - protected_icon_margin
        y = fullname.size().height() + self.TOP_MESSAGE_MARGIN
        painter.translate(x, y)
        message = self.__render_status_message(cell_width, index)
        message.drawContents(painter)
        accumulated_height += y + message.size().height()

        # Draw reposted by
        x = self.BOX_MARGIN + 16 - (self.LEFT_MESSAGE_MARGIN + self.AVATAR_SIZE)
        y = message.size().height() + self.BOTTOM_MESSAGE_MARGIN
        if accumulated_height < self.AVATAR_SIZE:
            y += (self.AVATAR_SIZE - accumulated_height) + self.COMPLEMENT_HEIGHT
        painter.translate(x, y)

        reposted_by = index.data(self.RepostedRole).toPyObject()
        if reposted_by:
            reposted = QTextDocument()
            reposted.setHtml("<span style='color: #999;'>%s</span>" % reposted_by)
            reposted.setDefaultFont(FOOTER_FONT)
            reposted.setTextWidth(self.__calculate_text_width(cell_width))
            reposted.drawContents(painter)

            # Draw reposted icon
            rect2 = QRect(-16, 3, 16, 16)
            painter.drawPixmap(rect2, self.reposted_icon)

        # Draw datetime
        datetime = index.data(self.DateRole).toPyObject()
        timestamp = QTextDocument()
        timestamp.setHtml("<span style='color: #999;'>%s</span>" % datetime)
#.........这里部分代码省略.........
开发者ID:Bouska,项目名称:Turpial,代码行数:103,代码来源:column.py

示例13: MessageItemDelegate

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import idealWidth [as 别名]
class MessageItemDelegate(QStyledItemDelegate):
    def __init__(self, parentView, logger, column=None, margin=50):
        super(MessageItemDelegate, self).__init__(parentView)

        self.logger = logger
        # We need that to receive mouse move events in editorEvent
        parentView.setMouseTracking(True)

        # Revert the mouse cursor when the mouse isn't over 
        # an item but still on the view widget
        parentView.viewportEntered.connect(self.unsetParentCursor)

        self.document = QTextDocument()
        self.mouseOverDocument = self.document
        self.mouseOverDocumentRow = -1
        self.mouseOverOption = None
        self.lastTextPos = QPoint(0, 0)
        self._editIndex = None
        self._editor = None
        self._column = column
        self._margin = margin
        
        ownGradient = QLinearGradient(0, 0, 0, 10)
        ownGradient.setColorAt(0, QColor(229, 239, 254))
        ownGradient.setColorAt(1, QColor(182, 208, 251))
        self._ownBrush = QBrush(ownGradient)
        self._ownPenColor = QColor(104, 126, 164)
        
        otherGradient = QLinearGradient(0, 0, 0, 10)
        otherGradient.setColorAt(0, QColor(248, 248, 248))
        otherGradient.setColorAt(1, QColor(200, 200, 200))
        self._otherBrush = QBrush(otherGradient)
        self._otherPenColor = QColor(153, 153, 153)
        
        self._timeFont = QFont("default", 12, QFont.Bold)
        
        self.closeEditor.connect(self.editorClosing)
        
        self._rowHeights = {}
        
    @loggingSlot()
    def unsetParentCursor(self):
        self.parent().unsetCursor()
        
    def setEditIndex(self, modelIndex):
        self._editIndex = modelIndex
        
    def getEditIndex(self):
        return self._editIndex
        
    @loggingSlot(QWidget, QAbstractItemDelegate.EndEditHint)
    def editorClosing(self, _editor, _hint):
        self._editor = None
        self.setEditIndex(None)
        
    def getEditor(self):
        return self._editor
    
    def createEditor(self, parent, option_, modelIndex):
        self.setEditIndex(modelIndex)
        
        option = QStyleOptionViewItemV4(option_)
        self.initStyleOption(option, modelIndex)
        
        text = QString(option.text)
    
        editorWidget = EditorWidget(parent)
        editor = ItemEditor(text, self._preferredMessageWidth(option.rect.width()), editorWidget)
        editorWidget.setItemEditor(editor)

        messageRect = self._getMessageRect(option, editor.document(), modelIndex, relativeToItem=True)
        pos = messageRect.topLeft()
        editor.move(pos)
        editor.resize(messageRect.size())
        
        self._editor = editorWidget
        return editorWidget
    
    def setModelData(self, *_args, **_kwargs):
        pass
    
    def _preferredMessageWidth(self, textRectWidth):
        return textRectWidth - self._margin
    
    def _getMessageRect(self, option, doc, modelIndex, relativeToItem=False):
        rightAligned = modelIndex.data(ChatMessagesModel.OWN_MESSAGE_ROLE).toBool()
        statusIcon = modelIndex.data(ChatMessagesModel.STATUS_ICON_ROLE)
        hasStatusIcon = statusIcon != None and not statusIcon.isNull()
        textRect = option.rect
        
        documentWidth = doc.idealWidth()
        if rightAligned:
            xOffset = textRect.width() - documentWidth - 3
            if hasStatusIcon:
                xOffset -= 20
        else:
            xOffset = 3
            if hasStatusIcon:
                xOffset += 20
        
#.........这里部分代码省略.........
开发者ID:hannesrauhe,项目名称:lunchinator,代码行数:103,代码来源:message_item_delegate.py


注:本文中的PyQt4.QtGui.QTextDocument.idealWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。