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. Dynamically creating GUIs on the same window

Dynamically creating GUIs on the same window

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 2.8k 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.
  • F Offline
    F Offline
    Flurite
    wrote on last edited by
    #1

    I am trying to dynamically instance new GUIs on to the current widget window. I tried doing this:

    @QLabel* newLabel = new QLabel("Hello");
    newLabel->show()@

    but that creates a new window with that widget.

    Is it possible to dynamically create widgets on the same window?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DerManu
      wrote on last edited by
      #2

      You'll need to set the parent to the respective window. I.e. use the constructor that takes the label string as first and the parent QWidget as second argument.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        Flurite
        wrote on last edited by
        #3

        Would I set the parent to the centralWidget in order for the widget to appear on the same window? That's the default object I believe.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DerManu
          wrote on last edited by
          #4

          Yes, for example.

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

            Also, check out QLayout to control how you arrange your new widgets. Use centralWindow->setLayout() first, and then you can dynamically call addWidget() on the layout.

            I'd start with "QVBoxLayout":http://qt-project.org/doc/qt-4.8/qvboxlayout.html or "QHBoxLayout":http://qt-project.org/doc/qt-4.8/qhboxlayout.html (vertical or horizontal boxes), and move on to more advanced layouts after that.

            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