QGraphicsTextItem:如何让鼠标移动区更宽?

时间:2017-03-29 12:19:40

标签: python pyqt pyqt5 qgraphicsscene qgraphicsitem

我的QGraphicsTextItem上有一个QGraphicsScene。我让它可编辑,我也希望有时用鼠标移动它(也可以用鼠标选择)。

但要移动它,我应该将鼠标指针放在文本区域和QGraphicsTextItem边框之间的几个像素中。

The selection area is too narrow!!!!!

你不能告诉我:如何使这个窄填充至少宽两倍?

以下是代码:

import sys

from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import QGraphicsItem, QGraphicsTextItem


if __name__ == "__main__":

    #########################################
    sys._excepthook = sys.excepthook
    def exception_hook(exctype, value, traceback):
        sys._excepthook(exctype, value, traceback)
        sys.exit(1)
    sys.excepthook = exception_hook
    ##########################################



    app = QtWidgets.QApplication(sys.argv)

    view = QtWidgets.QGraphicsView()
    view.setRenderHint(QtGui.QPainter.Antialiasing)
    view.setMouseTracking(True)
    view.setDragMode(QtWidgets.QGraphicsView.RubberBandDrag)

    scene = QtWidgets.QGraphicsScene()

    text_item = QGraphicsTextItem("Hell yeah!!!")
    text_item.setTextInteractionFlags(QtCore.Qt.TextEditorInteraction)
    text_item.setFlags(QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemIsFocusable | QGraphicsItem.ItemIsMovable)
    scene.addItem(text_item)

    view.setScene(scene)
    view.show()

    app.setStyle("fusion")

    sys.exit(app.exec_())

0 个答案:

没有答案