Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Change the central widget of QMainWindow

Change the central widget of QMainWindow

Scheduled Pinned Locked Moved General and Desktop
6 Posts 5 Posters 13.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kekule
    wrote on last edited by
    #1

    Hi,
    I have many widgets I derived from QWidget and I want to use them as central widget each time it is needed, how can I do this?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JvdGlind
      wrote on last edited by
      #2

      Try this:
      http://qt-project.org/doc/qt-5/qmainwindow.html#setCentralWidget

      Jeffrey VAN DE GLIND
      Principle Consultant @ Nalys
      www.nalys-group.com

      1 Reply Last reply
      0
      • JeroentjehomeJ Offline
        JeroentjehomeJ Offline
        Jeroentjehome
        wrote on last edited by
        #3

        Hmm,
        Would it not be better to have stackedWidget be placed in the centralWidget and then simply set a different widget on top??

        Greetz, Jeroen

        1 Reply Last reply
        0
        • A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          Yea I don't think changing the central widget works. I believe I read in the qt docs that it was unsupported. Although this could have been a long time ago and changed.

          I would go with Jeroentje's solution and put a central stacked widget and then just change what it shows. In fact that is the exact approach I have used in the past when I needed this behavior.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kekule
            wrote on last edited by
            #5

            Thanks a lot, that was very helpful. I've just passed my las 3 hours for searching about clearing the qwidget surface and repaint it with what I want. Through Qt doc, I think it is not possible, that is very stressful!!! Thanks for your help, I did this because I'm wondering how to handle the changing of my window title...

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              [quote author="kekule" date="1403829537"]I did this because I'm wondering how to handle the changing of my window title...[/quote]
              @mainWindow->setWindowTitle()@

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved