【发布时间】: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