當前位置: 首頁>>代碼示例>>Python>>正文


Python QGraphicsSimpleTextItem.setPen方法代碼示例

本文整理匯總了Python中PyQt4.QtGui.QGraphicsSimpleTextItem.setPen方法的典型用法代碼示例。如果您正苦於以下問題:Python QGraphicsSimpleTextItem.setPen方法的具體用法?Python QGraphicsSimpleTextItem.setPen怎麽用?Python QGraphicsSimpleTextItem.setPen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt4.QtGui.QGraphicsSimpleTextItem的用法示例。


在下文中一共展示了QGraphicsSimpleTextItem.setPen方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ugly_name_face

# 需要導入模塊: from PyQt4.QtGui import QGraphicsSimpleTextItem [as 別名]
# 或者: from PyQt4.QtGui.QGraphicsSimpleTextItem import setPen [as 別名]
def ugly_name_face(node, *args, **kargs):
    """ This is my item generator. It must receive a node object, and
    returns a Qt4 graphics item that can be used as a node face.
    """

    # receive an arbitrary number of arguments, in this case width and
    # height of the faces
    width = args[0][0]
    height = args[0][1]

    ## Creates a main master Item that will contain all other elements
    ## Items can be standard QGraphicsItem
    # masterItem = QGraphicsRectItem(0, 0, width, height)
    
    # Or your custom Items, in which you can re-implement interactive
    # functions, etc. Check QGraphicsItem doc for details.
    masterItem = InteractiveItem(0, 0, width, height)

    # Keep a link within the item to access node info 
    masterItem.node = node 

    # I dont want a border around the masterItem
    masterItem.setPen(QPen(QtCore.Qt.NoPen))

    # Add ellipse around text
    ellipse = QGraphicsEllipseItem(masterItem.rect())
    ellipse.setParentItem(masterItem)
    # Change ellipse color
    ellipse.setBrush(QBrush(QColor( random_color())))

    # Add node name within the ellipse
    text = QGraphicsSimpleTextItem(node.name)
    text.setParentItem(ellipse)
    text.setPen(QPen(QPen(QColor("white"))))

    # Center text according to masterItem size
    tw = text.boundingRect().width()
    th = text.boundingRect().height()
    center = masterItem.boundingRect().center()
    text.setPos(center.x()-tw/2, center.y()-th/2)
    
    return masterItem
開發者ID:xguse,項目名稱:ete,代碼行數:44,代碼來源:item_faces.py


注:本文中的PyQt4.QtGui.QGraphicsSimpleTextItem.setPen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。