Results 1 to 4 of 4

Thread: Reusing the same widget to implement "split-screen"

  1. #1
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Reusing the same widget to implement "split-screen"

    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.



    Thanks for your help,
    Thomas

  2. #2
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Reusing the same widget to implement "split-screen"

    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.

  3. The following user says thank you to ars for this useful post:

    thomab (30th January 2011)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Reusing the same widget to implement "split-screen"

    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

  5. The following user says thank you to ChrisW67 for this useful post:

    thomab (30th January 2011)

  6. #4
    Join Date
    Jan 2011
    Posts
    3
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Reusing the same widget to implement "split-screen"

    Thanks, this seems to work just fine.
    Guess I should have posted it in the newbie section.

Similar Threads

  1. How can i implement "Undo" action?
    By suseway in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2010, 11:32
  2. Replies: 1
    Last Post: 15th June 2009, 17:28
  3. How would you implement a "sticky" cursor?
    By spagatoni in forum Qt Programming
    Replies: 0
    Last Post: 4th May 2009, 20:56
  4. [QT3] Implement "Freeze Panes" features in QListView
    By Syphius in forum Qt Programming
    Replies: 7
    Last Post: 5th January 2009, 21:25
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.