- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个非常简单的 QGraphicsScene 派生类:
class SceneComponent : public QGraphicsScene
{
Q_OBJECT
public:
explicit SceneComponent(QObject* parent = 0);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent*);
};
mousePressEvent(QGraphicsSceneMouseEvent*)
定义为:
void SceneComponent::mousePressEvent(QGraphicsSceneMouseEvent* event) {
Q_UNUSED(event);
std::cout<<"[Processing] MouseEvent"<<std::endl;
}
要显示这个 QGraphicsView,这很简单:
QGraphicsView view(sceneComp);
view.show();
现在,当我单击显示的窗口(对于 QGraphicsView)时,我得到以下输出:
[Processing] MouseEvent
[Processing] MouseEvent
但是,当我使用以下方式发送合成事件时:
QMouseEvent* mevent = new QMouseEvent(
QMouseEvent::MouseButtonPress, QPoint(50, 50),
Qt::LeftButton, Qt::NoButton, Qt::NoModifier
);
QApplication::sendEvent(&view, mevent);
我完全没有输出。这是为什么?
相关说明,在 QGraphicsScene 上安装 eventFilter
根本不会产生任何结果。这可能(在我看来)是因为 QGraphicsScene 需要 QGraphicsSceneMouseEvent 而不是 QMouseEvent。这支持了两个问题:
最佳答案
来自 QGraphicsSceneEvent
的文档:
When a QGraphicsView receives Qt mouse, keyboard, and drag and drop events (QMouseEvent, QKeyEvent, QDragEvent, etc.), it translates them into instances of QGraphicsSceneEvent subclasses and forwards them to the QGraphicsScene it displays. The scene then forwards the events to the relevant items.
For example, when a QGraphicsView receives a QMouseEvent of type MousePress as a response to a user click, the view sends a QGraphicsSceneMouseEvent of type GraphicsSceneMousePress to the underlying QGraphicsScene through its mousePressEvent() function. The default QGraphicsScene::mousePressEvent() implementation determines which item was clicked and forwards the event to QGraphicsItem::mousePressEvent().
QGraphicsView
使用视口(viewport)小部件来显示场景的内容并接收用户事件。尝试将您的事件发送到 QGraphicsView::viewport()
小部件 - 它应该可以工作。QMouseEvent
与 body Action 相关 - 例如。鼠标点击,同时 QGraphicsSceneMouseEvent
是抽象的东西...QGraphicsScene
有QObject
级别事件,与 QApplication::sendEvent()
一起发送, 和 QGraphicsItem
与 QGraphicsScene::sendEvent()
一起发送的事件.这两种工作在不同的层面,有不同的目的。有关详细信息,请参阅文档。关于c++ - QGraphicsScene 不响应合成事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5080181/
再会! 对于 Qt 4.7.3,下面的示例在 QGraphicsScene::~QGraphicsScene() 调用时崩溃: #include #include int main( int ar
我正在尝试将图像添加到 QGraphicsView/QGraphicsScene 以便稍后我可以根据用户的输入在其上绘制简单的几何图形。我需要确保图像适合 QGraphicsView 而不管其纵横比如
根据 Qt 规范 QGraphicsScene 是一个viewless QGraphicsItems 的数据模型。 我有一个可以在窗口和非窗口模式下使用的工具 (当为其提供命令行参数时)。 在非窗口模
我有一个 QGraphicsScene上面有图形和文字。当我尝试打印时,图形很好,但文本使用以磅为单位定义的字体大小,因此 scene->render()当我通过它时 QPainter用 QPrint
他们想在按下和移动鼠标按钮时拖动这条贝塞尔曲线.. 我这样做了: void MainWindow::mouseMoveEvent(QMouseEvent *e) { qDebug()buttons()
使用下面的代码片段,我创建了一个包含 100.000 个矩形的场景。 表现不错; View 响应没有延迟。 QGraphicsScene * scene = new QGraphicsScene; f
我试图了解如何在 QGraphicsScene 中重新定义选择和转换项目(一旦选择)的方式。 .例如改变一条线的长度,移动一条线,通过移动一个点来改变一个多边形。 我创建了一个 QGraphicsVi
我正在使用 QGraphicsScene 类。如何检测鼠标离开 QGraphicsScene ?是否有任何内部函数可以实现此目的? 最佳答案 如果您想检测释放事件,您必须覆盖 mouseRelease
我有一个小部件,它分为两个子小部件。一个显示图片,另一个提供编辑图片的选项。图片子部件的水平空间应是编辑子部件的 5 倍。我在网格布局中指定此约束。但是,一旦我将 QGraphicsScene(和 V
我创建了一个小应用程序,我试图使其在调整主窗口大小(GraphicsView 和场景也是如此)时整个场景(像素图和矩形)垂直缩放以完全适合内部图形 View 。我不想要垂直滚动条,也不希望它水平缩放。
我有一个 QGraphicsScene,我已经确定了我的中心点在哪里,但我现在需要弄清楚如何根据该信息将我的项目放置在场景中。 我有 2 条数据需要处理:距离和方位。 Range 显然是距离中心点(或
我想在我的主窗口中跟踪鼠标。我在 QGraphicsView 中启用了 moustracking这是 GraphicsView 子类的构造函数,其余是默认行为。 GraphicsView::Graph
我有一个非常简单的 QGraphicsScene 派生类: class SceneComponent : public QGraphicsScene { Q_OBJECT public:
我正在尝试使用 qgraphicsview qgraphicsitem 来创建像国际象棋一样的场景。 我正在按照官方示例尝试创建它,但没有显示任何内容。代码几乎是一样的。首先,我想知道是我的 Cell
我正在尝试将 QgraphicsView(QColorDialog) 小部件添加到 Palette 对话框中,但是 QGraphicsScene 对应于 QColorDialog 小部件总是空白,如果
我有这样的程序:在我的小部件中,我有 qpushbuttons、qslider 和 qgraphicsview。我将 qgraphicsscene 放在 qgraphicsview 中。问题是,当我在
我正在创建一个显示 QGraphicsScene 的 QGraphicsView。 我将场景的背景设置为 QImage 位图,其中: scene()->setBackgroundBrush(myQIm
我有一个从某个位置向上移动的椭圆。 void Equalizer::advance(int phase) { if(!phase) return; QPointF location =
我的目标: 我想在 QGraphicsView 上的位置 x = 0,y = 0 处绘制一个长度和宽度为 100 的简单矩形。那应该看起来像这样 到目前为止我做了什么我在主页(MainWindow)的
我正在 Qt 5.1 中编写一个小型 CAD 应用程序,我正在尝试弄清楚如何使 QGraphicsScene 的坐标与真实世界的尺寸相对应。例如,我打算将坐标保持在其原始形式(值,单位),以便在从毫米
我是一名优秀的程序员,十分优秀!