PDA

View Full Version : Reusing the same widget to implement "split-screen"



thomab
28th January 2011, 19:30
Hi,

first of all I'm new to Qt and GUI programming, but I do have plenty of C++ experience.

So I am trying to make a program (Widget?) which can open an image and do some simple image processing.
But I want to have two copies of the same widget displayed side-by-side so I can compare images (and other reasons).
Now in all my object-oriented glory I decided to just finish the single widget first, and when done just instantiate
two instances and place them side by side in a QMainWindow.

I created a new project (as a QWidget) and finished it, but now I don't know how to instantiate two of versions
of the widget and place them next to each other in a main window. I have tried reading about creating a plugin
for Qt designer, but that seems like a lot of work for a simple problem.

Right now I have tried to create a new project (using QMainWindow this time), but I can't figure out how to instantiate the
two QWidgets I made in the previous project. I want the GUI to look like the picture, the QWidget (which is finished, in another project)
is marked in red.

http://i.imgur.com/PsuYI.png

Thanks for your help,
Thomas

ars
28th January 2011, 19:52
Move the code implementing the "red box widget" from your previous project into the new one based on QMainWindow.
In QMainWindow, create a QSplitter and set it as QMainWindow central widget. Create two instances of your red box widget and add them to the QSplitter instance.

ChrisW67
28th January 2011, 19:53
Put your two instances inside a container QWidget using a QHBoxLayout or QSplitter. Set that container widget as the QMainWindow::centralWidget().

Edit: beaten to it

thomab
29th January 2011, 15:57
Thanks, this seems to work just fine.
Guess I should have posted it in the newbie section.