简体   繁体   English

如何同步多个QT图形视图小部件之间的移动

[英]How to synchronize movement between multiple QT graphics view widgets

I am trying to build a tool that can compare images side-by-side. 我正在尝试构建可以并行比较图像的工具。 To do this, I have used three graphics view widgets in QT. 为此,我在QT中使用了三个图形视图小部件。 They all zoom at the same rate, but I cannot seem to find anything online about how to link the movement of the images (aka - the drag and drop with the mouse). 它们都以相同的速度缩放,但是我似乎无法在网上找到有关如何链接图像运动的任何东西(又名-用鼠标拖放)。 Is this feature even possible to construct? 是否可以构建此功能?

Here is what the GUI looks like: GUI如下所示:

Image compare GUI 图像比较GUI

Well, every time I used a QGraphicsView, I ended up subclassing it cause it didn't provide everything I needed "as public". 嗯,每次我使用QGraphicsView时,我都会对其进行子类化,因为它没有“公开”提供我所需的一切。

In your case though, I believe this is as simple as doing: 但就您的情况而言,我认为这很简单:

connect(graphicsView1->verticalScrollBar(), SIGNAL(valueChanged(int)),
        graphicsView2->verticalScrollBar(), SLOT(setValue(int)));
connect(graphicsView2->verticalScrollBar(), SIGNAL(valueChanged(int)),
        graphicsView1->verticalScrollBar(), SLOT(setValue(int)));

If you prefer, call some slots to perform more than a 1-to-1 action: 如果愿意,请调用一些插槽以执行一对多的操作:

void MyClass::scrollGraphicsView1(int value)
{
    graphicsView1->verticalScrollBar()->setValue(value);
}
void MyClass::scrollGraphicsView2(int value)
{
    graphicsView2->verticalScrollBar()->setValue(value);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM