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. QWidget on top of other QWidget
Qt 6.11 is out! See what's new in the release blog

QWidget on top of other QWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 4.1k Views
  • 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.
  • Z Offline
    Z Offline
    zed962
    wrote on last edited by zed962
    #1

    Hello all,

    I am trying to create the following design on Qt.

    0_1490357920834_capture.png

    https://s27.postimg.org/knqu9zvyr/capture.png

    Mainly I want to place a QWidget on top of another. What's the best way of doing it? There are few links online explaining this process and none of them worked.

    Thanks,

    J.HilkJ 1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Image upload doesn't work, please use an external service, see https://forum.qt.io/topic/62615/how-to-insert-image-on-this-forum

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      Z 1 Reply Last reply
      0
      • VRoninV VRonin

        Image upload doesn't work, please use an external service, see https://forum.qt.io/topic/62615/how-to-insert-image-on-this-forum

        Z Offline
        Z Offline
        zed962
        wrote on last edited by
        #3

        @VRonin edited my post, thanks a lot

        1 Reply Last reply
        0
        • Z zed962

          Hello all,

          I am trying to create the following design on Qt.

          0_1490357920834_capture.png

          https://s27.postimg.org/knqu9zvyr/capture.png

          Mainly I want to place a QWidget on top of another. What's the best way of doing it? There are few links online explaining this process and none of them worked.

          Thanks,

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @zed962

          hi,
          thats simple enough, here's a short example:

          QWidget *widget1 = new QWidget();
          widget1->setObjectName("w1");
          widget1->resize(200,200);
          ...
          
          
          QWidget * widget2 = new QWidget(widget1);
          widget2->resize(100,100);
          widget2->setObjectName("w2");
          widget2->move(50,50);
          ...
          
          widget1->setStyleSheet(QWidget#w1{background-color:red;}"
                                                          QWidget#w2{background-color:blue;}");
          widget1->show();
          

          this creates a blue widgets on top of a red one.


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          Z 1 Reply Last reply
          1
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by VRonin
            #5

            http://doc.qt.io/qt-5/qtwidgets-layouts-basiclayouts-example.html

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            1
            • J.HilkJ J.Hilk

              @zed962

              hi,
              thats simple enough, here's a short example:

              QWidget *widget1 = new QWidget();
              widget1->setObjectName("w1");
              widget1->resize(200,200);
              ...
              
              
              QWidget * widget2 = new QWidget(widget1);
              widget2->resize(100,100);
              widget2->setObjectName("w2");
              widget2->move(50,50);
              ...
              
              widget1->setStyleSheet(QWidget#w1{background-color:red;}"
                                                              QWidget#w2{background-color:blue;}");
              widget1->show();
              

              this creates a blue widgets on top of a red one.

              Z Offline
              Z Offline
              zed962
              wrote on last edited by
              #6

              @J.Hilk That just shows the colors, what if i had buttons inside the QWidget, can i still control these? Thank you for helping out!

              J.HilkJ 1 Reply Last reply
              0
              • Z zed962

                @J.Hilk That just shows the colors, what if i had buttons inside the QWidget, can i still control these? Thank you for helping out!

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by J.Hilk
                #7

                @zed962

                sure its possible, every widget can have multiple children of its own.

                You can either create and handle that all by yourself - that however might get quickly become complex and complicated - Or You use the tools Qt- provides for this, Like QLayouts, QStackedWidgets, QTabWidgets etc.

                Qt comes with QtDesigner made to help you create a basic design via drag and drop.

                But I recommend @VRonin 's link that should get you started and help you understand the basics of creating a Ui by code.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1

                • Login

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