Results 1 to 4 of 4

Thread: Application with two MainWindows (switchable)

  1. #1
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Application with two MainWindows (switchable)

    Hi folks,

    I'm trying to write a new Gui (switchable) for a existing Qt-Application (V 4.8.4). So I Created a new QMainWindow (bisides the old one) and an other more QMainWindow two host the two MainWindows shown to the user. My Approach was to add them as centralWidget to "HostWidget".
    the Problem is, that the other MainWindows are not the central widget of the "HostWidget" - it is just lying over it. Everthing else works fine however. So my Quastions are:

    1) Is it possible to set a QMainWidget as a central widget. As far as I understand is a QMainWindow just a Widget with some bars and docking manager included.

    2) I tried to add a stack widget and than added two MainWindows to this QStackWidget. But it is also not exactly what I want, since a StackWidget is intended to host widget whitch are already instanciated and conviniently switch them via index. However, no othe Window than one of the two Mainwindows are visible.

    3) Or is there an other approach to create a gui with two Mainwindos that can be switched?

    Thanks in advance

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Application with two MainWindows (switchable)

    Lets say you want to host 2 (or multiple) MainWindows in a QMainWindow. Add the MainWindows to a layout, and then put this layout on a QWidget, set this QWidget as the central widget of QMainWidget.

    I only problem I see that MainWindow will loose it's MenuBar, as it not a top level window anymore.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Mar 2017
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Application with two MainWindows (switchable)

    Thanks alot for your suggestion. I have got it work with approach 1). But I had to set the window flag of the Mainwindows to host as a central widget to Qt::Widget (using QMainWindow::setWindowFalg).
    But now I have an onther Problem, that the hosted window is shown just after it is created but before it is set to be the central widget. So there is like a little "flicker" when I start the Application or switch the windows. Even if I trie to hide them before. The effect it also present, when I used approach 2) and abused the QStackedWidget for my job...

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Application with two MainWindows (switchable)

    Quote Originally Posted by pothead42 View Post
    1). But I had to set the window flag of the Mainwindows to host as a central widget to Qt::Widget (using QMainWindow::setWindowFalg)
    That should not be required.

    Quote Originally Posted by pothead42 View Post
    Even if I trie to hide them before.
    No need to hide, just don't show them in the first place, just add to layout and only show the host QMainWindow (top level window)
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Signal to Progressbar in Mainwindows Statusbar
    By ckvsoft in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2016, 10:45
  2. Replies: 2
    Last Post: 20th April 2016, 16:52
  3. MainWindows
    By Maluko_Da_Tola in forum Newbie
    Replies: 2
    Last Post: 25th August 2010, 07:08
  4. multiple mainwindows
    By JeanC in forum Qt Programming
    Replies: 4
    Last Post: 4th February 2008, 19:22
  5. Proper way of using Designer for MainWindows
    By Doug Broadwell in forum Newbie
    Replies: 1
    Last Post: 11th October 2006, 08:20

Tags for this Thread

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.