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


Python QTextDocument.size方法代码示例

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


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

示例1: displayAnnotation

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [as 别名]
 def displayAnnotation(self, geom, message):
     ''' Display a specific message in the centroid of a specific geometry 
     '''
     centroid = geom.centroid()
     
     # clean previous annotations:
     for annotation in self.annotations:
         try:
             scene = annotation.scene()
             if scene:
                 scene.removeItem(annotation)
         except:
             # annotation can be erased by QGIS interface
             pass
     self.annotations = []
     
     # build annotation
     textDoc = QTextDocument(message)
     item = QgsTextAnnotationItem(self.iface.mapCanvas())
     item.setMapPosition(centroid.asPoint())
     item.setFrameSize(textDoc.size())
     item.setDocument(textDoc)
     item.update()
     
     # add to annotations
     self.annotations.append(item)
     
     # center in the centroid
     self.iface.mapCanvas().setCenter(centroid.asPoint())
     self.iface.mapCanvas().zoomScale(float(self.defaultZoomScale))
     self.iface.mapCanvas().refresh()
开发者ID:psigcat,项目名称:searchplus,代码行数:33,代码来源:search_plus.py

示例2: FeatureShape

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [as 别名]
class FeatureShape(LabeledPolygonShape):

    def draw(self, painter, xMap, yMap, canvasRect):
        self._setup_painter(painter)

        self._set_outer_pen_and_brush(painter, xMap, yMap)
        rtmin = self.item.rtmin
        rtmax = self.item.rtmax
        mzmin = self.item.mzmin
        mzmax = self.item.mzmax
        self._draw_polygon(painter, xMap, yMap, (rtmin, rtmax, mzmin, mzmax))

        self._set_inner_pen_and_brush(painter, xMap, yMap)
        for mass_trace in self.item.mass_traces:
            self._draw_polygon(painter, xMap, yMap, mass_trace)

        if self.label is not None:
            self._draw_label(painter, xMap, yMap)

    def _draw_label(self, painter, xMap, yMap):
        self.text = QTextDocument()
        self.text.setDefaultStyleSheet("""div { color: rgb(%d, %d, %d); }""" % self.color)
        self.text.setHtml("<div>%s</div>" % (self.label, ))

        x0 = xMap.transform(self.item.rtmax)
        # y0: height between m0 and m1 masstrace if m1 exists, else at height of m0
        yi = sorted(m.mzmin for m in self.item.mass_traces)
        if len(yi) >= 2:
            y0 = yMap.transform(0.5 * yi[0] + 0.5 * yi[1])
        else:
            y0 = yMap.transform(yi[0])
        h = self.text.size().height()
        painter.translate(x0, y0 - 0.5 * h)
        self.text.drawContents(painter)
开发者ID:uweschmitt,项目名称:ivi,代码行数:36,代码来源:peakmapplotter.py

示例3: show

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [as 别名]
def show(cursor, pos=None, num_lines=6):
    """Displays a tooltip showing part of the cursor's Document.
    
    If the cursor has a selection, those blocks are displayed.
    Otherwise, num_lines lines are displayed.
    
    If pos is not given, the global mouse position is used.
    
    """
    block = cursor.document().findBlock(cursor.selectionStart())
    c2 = QTextCursor(block)
    if cursor.hasSelection():
        c2.setPosition(cursor.selectionEnd(), QTextCursor.KeepAnchor)
        c2.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
    else:
        c2.movePosition(QTextCursor.NextBlock, QTextCursor.KeepAnchor, num_lines)
    
    data = textformats.formatData('editor')
    
    doc = QTextDocument()
    font = QFont(data.font)
    font.setPointSizeF(font.pointSizeF() * .8)
    doc.setDefaultFont(font)
    doc.setPlainText(c2.selection().toPlainText())
    if metainfo.info(cursor.document()).highlighting:
        highlighter.highlight(doc, state=tokeniter.state(block))
    size = doc.size().toSize() + QSize(8, -4)
    pix = QPixmap(size)
    pix.fill(data.baseColors['background'])
    doc.drawContents(QPainter(pix))
    label = QLabel()
    label.setPixmap(pix)
    label.setStyleSheet("QLabel { border: 1px solid #777; }")
    label.resize(size)
    widgets.customtooltip.show(label, pos)
开发者ID:WedgeLeft,项目名称:frescobaldi,代码行数:37,代码来源:documenttooltip.py

示例4: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [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

示例5: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [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

示例6: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [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

示例7: sizeHint

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [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 size [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

示例9: PeakRangeShape

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [as 别名]
class PeakRangeShape(LabeledPolygonShape):

    def draw(self, painter, xMap, yMap, canvasRect):
        self._setup_painter(painter)
        self._set_inner_pen_and_brush(painter, xMap, yMap)
        self._draw_polygon(painter, xMap, yMap, self.item)

        if self.label is not None:
            self._draw_label(painter, xMap, yMap)

    def _draw_label(self, painter, xMap, yMap):
        self.text = QTextDocument()
        self.text.setDefaultStyleSheet("""div { color: rgb(%d, %d, %d); }""" % self.color)
        self.text.setHtml("<div>%s</div>" % (self.label, ))

        x0 = xMap.transform(self.item.rtmax)
        # y0: height between m0 and m1 masstrace if m1 exists, else at height of m0
        y0 = yMap.transform(0.5 * self.item.mzmin + 0.5 * self.item.mzmax)
        h = self.text.size().height()
        painter.translate(x0, y0 - 0.5 * h)
        self.text.drawContents(painter)
开发者ID:uweschmitt,项目名称:ivi,代码行数:23,代码来源:peakmapplotter.py

示例10: MessageItemDelegate

# 需要导入模块: from PyQt4.QtGui import QTextDocument [as 别名]
# 或者: from PyQt4.QtGui.QTextDocument import size [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.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。