How To: Compare two Images visually with Splitter
-
Hi all,
I want to display two similar images one on top of each other.
A "vertical splitter like item" should be used to enlarge/downsize the visible area.
This implicates, that both images are placed on top of each other at the same position.I tried to use 2 labels and a splitter object, but both images are displayed side by side instead on top of each other. Any ideas how I can achieve the desired functionality?
//Load images QPixmap image1(":img1"); QPixmap image2(":img2"); //Create Elements QLabel *label1 = new QLabel; label1->setPixmap(image1); QLabel *label2 = new QLabel; label2->setPixmap(image2); // Create a QSplitter to create the split view QSplitter *splitter = new QSplitter(Qt::Horizontal); splitter->addWidget(label1); splitter->addWidget(label2); splitter->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // Set the central widget of the MainWindow to contain the splitter QWidget *centralWidget = new QWidget; QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(splitter); centralWidget->setLayout(layout); setCentralWidget(centralWidget);
-
@ademmler
Maybe I am misunderstanding, if you are wanting "both images are placed on top of each other at the same position" you want to use absolute positioning on their parent? Then the top image would obscure the one underneath it, unless areas are transparent? Is that what you are wanting? -
Hi,
One possible way is to create a custom widget where you set both images and draw them on top of each other in a custom paintEvent. You would have to implement the separation bar handling yourself also.