五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

python編程使用PyQt創(chuàng)建UE藍(lán)圖

發(fā)布日期:2021-12-17 21:37 | 文章來源:源碼中國

實現(xiàn)思路

1、場地部署:我們需要擁有一個可以用來畫節(jié)點的地方!詳看我這篇文章QGraphicsScene、QGraphicsView的基礎(chǔ)使用,這篇文章用的也是同樣的方法PyQt制作預(yù)覽窗口(游戲中的小地圖)
2、節(jié)點創(chuàng)建:我們需要自定義節(jié)點,也就是下圖中的方框內(nèi)的東西,主要涉及到的就是Qt中的QGraphicsItem,通過繼承這個類來自定義節(jié)點樣式
3、連線:涉及到的就是Qt中的QGraphicsLineItem,繼承這個類,并在paint中自定義連線樣式,比如我這里使用的是qt自帶的貝塞爾曲線
實現(xiàn)的效果如下,節(jié)點之間可以通過端口互相連接

1、場地部署

class EditorView(QGraphicsView):
 def __init__(self, parent=None):
  super(EditorView, self).__init__(parent)
  self.parent = parent
  self.scaleFactor = 1
  self.lastPos = QPointF()
  self.scene = EditorScene(self)
  self.setScene(self.scene)
  self.setSceneRect(-1 << 30, -1 << 30, 1 << 31, 1 << 31)
  self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
  self.verticalScrollBar().setEnabled(False)
  self.horizontalScrollBar().setEnabled(False)
class EditorScene(QGraphicsScene):
 def __init__(self, parent=None):
  super(EditorScene, self).__init__(parent)
	def drawBackground(self, painter, rect):
		pass
		# 在這里畫底圖,也就是上面的方格圖

2、節(jié)點創(chuàng)建

下面是創(chuàng)建節(jié)點的主體,就那個黑框框的東西

class NodeItem(QGraphicsItem):
 def __init__(self, parent=None):
  super(NodeItem, self).__init__(parent)
  self.setFlag(QGraphicsItem.ItemIsMovable, True)
  self.setFlag(QGraphicsItem.ItemIsSelectable, True)
  self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
  self.setFlag(QGraphicsItem.ItemIsFocusable, True)
  self.nodeName = "Node"
  self.width = 150
  self.height = 50
		self.addPort()
 def addPort(self):
  leftPort = PortItem(self)
  leftPort.setPos(5, self.height/2.7)
  rightPort = PortItem(self)
  rightPort.setPos(self.width-20, self.height/2.7)
 def paint(self, painter, style, *args, **kwargs):
  brush = QBrush(QColor(0xaa, 0xaa, 0xaa, 0xaa))
  painter.setBrush(brush)
  pen = QPen()
  pen.setWidth(1)
  painter.setPen(pen)
  painter.drawRect(0, 0, self.width, self.height)
  painter.drawText(self.width/2.5, self.height/1.8, self.nodeName)

下面是節(jié)點端口的創(chuàng)建

class PortItem(QGraphicsItem):
 def __init__(self, parent=None):
  super(PortItem, self).__init__(parent)
  self.portDiam = 15
 def paint(self, painter, style, *args, **kwargs):
  portColor = QColor(0x00, 0xaa, 0x00, 0x66)
  painter.setBrush(portColor)
  pen = QPen()
  pen.setColor(portColor)
  pen.setWidth(2)
  painter.setPen(pen)
  painter.drawEllipse(0, 0, self.portDiam, self.portDiam)

在節(jié)點NodeItem里面,創(chuàng)建兩個端口用于連接

3、連線

①首先是連線類的創(chuàng)建

class LineItem(QGraphicsItem):
 def __init__(self, posStart, posEnd, parent=None):
  super(LineItem, self).__init__(parent)
  self.setFlag(QGraphicsItem.ItemIsSelectable, True)
  self.setFlag(QGraphicsItem.ItemSendsGeometryChanges, True)
  self.setFlag(QGraphicsItem.ItemIsFocusable, True)
  self.posStart = posStart
  self.posEnd = posEnd
 def paint(self, painter, style, *args, **kwargs):
  midPos = (self.posStart + self.posEnd)/2
  lineColor = QColor(0xff, 0x00, 0x00, 0xff)
  pen = QPen()
  pen.setColor(lineColor)
  pen.setWidth(2)
  painter.setPen(pen)
  linePath = QPainterPath()
  linePath.moveTo(self.posStart)
  linePath.cubicTo(QPointF(midPos.x(), self.posStart.y()), midPos, self.posEnd)
  painter.drawPath(linePath)

②如何連接節(jié)點

def mouseReleaseEvent(self, event):
	self.line = LineItem(self.portPosStart, self.portPosEnd)
 self.scene.addItem(self.line)

ps寫在最后,如果你的圖沒有刷新,你可以先把窗口縮小再打開,他就會刷新了,如果你想讓他自動刷新,就調(diào)用scene.update()方法吧!

以上就是python編程使用PyQt創(chuàng)建UE藍(lán)圖的詳細(xì)內(nèi)容,更多關(guān)于PyQt創(chuàng)建UE藍(lán)圖的資料請關(guān)注本站其它相關(guān)文章!

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

相關(guān)文章

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部