【问题标题】:Context Menu event with QGraphicsWidget带有 QGraphicsWidget 的上下文菜单事件
【发布时间】:2010-06-10 09:17:06
【问题描述】:

在我的应用程序中,我继承了 QGraphicsWidget
在油漆中,我正在画一条笔宽为 4 的线。
我重新实现了 boundingRect() 和 shape()。
但是每次单击鼠标右键时,我都无法捕获上下文菜单事件。
有什么问题。(笔宽?)

 //Sample code for boundingRect() and shape()
  QRectF boundingRect() const
  {
    qreal rectLeft = x1 < x2 ? x1 : x2;
    qreal rectTop = y1 < y2 ? y1 : y2;
    qreal rectWidth = (x1 - x2) != 0 ? abs(x1-x2) : 4;
    qreal rectHeight = (y1 - y2) != 0 ? abs(y1 -y2) : 4;

    return QRectF(rectLeft,rectTop,rectWidth,rectHeigt);
  }

  QPainterPath shape()
  {
    QPainterPath path;
    path.addRect(boundingRect());
    return path;
  }

【问题讨论】:

  • 你好,你的QGraphicView对象是透明的吗?你在哪里实现mouceClickEvent?给我多一点信息。
  • cnebrera 是对的,您的代码没有显示任何与处理鼠标事件相关的代码。再具体一点。 Afaik,你需要重新实现QWidget::contextMenuEvent

标签: c++ qt events qt4 contextmenu


【解决方案1】:

你也可以重新实现QWidget::mousePressEvent(),检查是否只有rightMouseButton被按下并调用你的方法,你将手动显示你的QMenu。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 1970-01-01
    相关资源
    最近更新 更多