- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
所以我有一个带有 QGraphicsPolygonItem 的 QraphicsScene ,我将其标记为可移动。我还重写了 MousePressEvent。我的代码片段现在已经出来了。
def mousePressEvent(self , e):
self.endx = e.x()
self.endy = e.y()
if self.sender == 1:
self.LineChange(self.endx , self.endy)
#...
def CreateFun(self):
poly = QtGui.QPolygonF([QtCore.QPointF(100 , 100) , QtCore.QPointF(100 , 200) , QtCore.QPointF(200 , 200)])
self.polygon = QtGui.QGraphicsPolygonItem(poly)
self.scene.addItem(self.polygon)
self.polygon.setFlag(QtGui.QGraphicsItem.ItemIsMovable)
但是多边形没有移动。当我注释掉 MousePressEvent 时,它移动得很好。我的猜测是 MousePressEvent 在 PolygonItem 之前捕获它。
而上述函数均来自于继承自QtGui.QGraphicsView的类。有什么建议吗?
最佳答案
您应该调用mousePressEvent
的基本实现。 QGraphicsView
通常会将这些点击传递给可能使用它们的其他项目。如果您不调用基本实现,那么您基本上就是在“捕获”点击。
修改您的mousePressEvent
如下:
def mousePressEvent(self , e):
self.endx = e.x()
self.endy = e.y()
if self.sender == 1:
self.LineChange(self.endx , self.endy)
# let the base implementation do its thing
super(Palette, self).mousePressEvent(e)
关于python - MousePressEvent 捕获不必要的信号 - PyQt4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14453799/
所以,我试图每次左键单击时打印鼠标位置,但它只能在布局之外工作,我不知道如何修复它。我的 GUI 看起来像这样: import sys from PyQt5 import QtGui, QtWidge
我有两个不同的类继承QGraphicsItem。它们都有各自特定的 mousePressEvent 函数。当这些项目在场景中重叠时,我只想执行其中一个项目的 mousePressEvent。我怎样才能
我正在尝试检测具有多个小部件的区域内任意位置的鼠标点击。为此,我使用以下代码: custom_widget = CustomWidget() custom_widget.mouse_pressed_s
我在使用 QGraphicsView 和 QGraphicsScene 时遇到了一些困难。当我在场景中缩放/取消缩放并使用 mousePressEvent 创建项目时,我在该位置有一个偏移量。如何避免
我想在 dicom 系列(使用 qt 和 vtk)上实现一些功能,并且我想在 qt 窗口和鼠标之间建立一些连接。 这是我的主要设计: 例如,如果我点击 zoombutton,然后我用鼠标左键点击我的图
如何进入方法 on_product_clicked,其中 QLabel 是一个 mousePressEvent? 在当前示例中,我在表单中看到了三个图像。当我点击第二张图片时,我需要在 on_prod
我正在尝试同时运行两个 QWidget::mousePressEvent() 处理程序。我有两个小部件,A 和 B。B继承自QLabel,A继承自QWidget。我已经在它们两个上重载了 QWidge
所以我有一个带有 QGraphicsPolygonItem 的 QraphicsScene ,我将其标记为可移动。我还重写了 MousePressEvent。我的代码片段现在已经出来了。 def mo
我有一个小部件,我想在用户按下鼠标时运行一些功能。但我只想在鼠标按下导致焦点改变时运行它。我尝试了以下方法: void MyWidget::mousePressEvent(QMouseEvent *e
我在使用 mousePressEvent(QGraphicsSceneMouseEvent *event) 时遇到问题,实际上可点击区域看起来很小并且偏离了它链接到的 QGraphicsPixmapI
在 Class Buttons 中,我有一个 btnRightClicked 信号和一个 mousePressEvent 插槽: void Buttons::mousePressEvent(QMous
请考虑以下代码: #include #include #include class Widget : public QWidget { public: void mousePressEv
我有一个包含多个子对象的小部件,用户可以通过单击它们来选择它们。 我想在用户点击小部件外部时清除当前选择,我想知道如何最好地检测这些点击。 一些约束: 通过eventFilter吃掉周围对象的mous
我正在尝试在 pyqt4 中调整照片查看器(我从本网站的另一个问题中获得了代码)。默认情况下,鼠标滚轮缩放,鼠标左键用于平移/拖动(不知道到底该怎么称呼)图像。我想添加左键单击图像时获取像素信息的功能
在最近的项目中,我尝试在 GraphicsView 中单击相应位置后在场景上绘制点,但没有任何反应。我将错误追踪到缺少对 ClickableMap::mousePressEvent(const QMo
我有一个继承自 qquickwindow 的对象,该对象具有重写的 mousePressEvent 方法。 .h class FWindow : public QQuickWindow { Q
我正在尝试子类化 QCheckBox 以使其在禁用时通过鼠标点击。当我的复选框未被禁用时(isEnabled() 为 true),Qt 按预期调用其 mousePressEvent()。当它被禁用时,
我有一个类,它是 QDialog 的子类,没有覆盖 exec()、accept() 或 reject() 和另一个调用 mousePaintEvent 中的 Dialog 类: void Canvas
为了熟悉 Qt 的图形 View ,我在 Qt 中实现了一个简单的棋盘。目前没有棋子。 我使用矩形来表示每个图 block ,所以我创建了 BoardTile 类(继承自 QGraphicsRectI
我在使用 installEventFilter 过滤 "mousePressEvent" 时遇到问题 MyTestxEdit 是一个包含 QTextEdit 的小部件我希望 QTextEdit 的所有
我是一名优秀的程序员,十分优秀!