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. Adding a custom widget into an existing layout.
Forum Updated to NodeBB v4.3 + New Features

Adding a custom widget into an existing layout.

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 4 Posters 2.1k Views 2 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.
  • M Offline
    M Offline
    m1212e
    wrote on last edited by m1212e
    #2

    Sooo, I got it. I think this is actually the proper way to do it, right? At least it's staying centered now. But the other qestions remain? Is this the way to do it?

    static_cast<QGridLayout *>(ui->gridLayout)->addWidget(b, 0, 1, Qt::AlignCenter);
    

    Thanks anyway for reading?

    1 Reply Last reply
    1
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #3

      @m1212e said in Adding a custom widget into an existing layout.:

      static_cast<QGridLayout *>(ui->gridLayout)

      Why do you need a cast here?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      M 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @m1212e said in Adding a custom widget into an existing layout.:

        static_cast<QGridLayout *>(ui->gridLayout)

        Why do you need a cast here?

        M Offline
        M Offline
        m1212e
        wrote on last edited by
        #4

        @Christian-Ehrlicher
        You're abolutely right :D
        It's just an artifact from previous attempts.
        Thanks!

        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #5

          When you won't add your widget by code but directly in the designer you can take a look at promoting widgets.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          M 1 Reply Last reply
          3
          • Christian EhrlicherC Christian Ehrlicher

            When you won't add your widget by code but directly in the designer you can take a look at promoting widgets.

            M Offline
            M Offline
            m1212e
            wrote on last edited by
            #6

            @Christian-Ehrlicher

            Already did that, but thanks. Unfortunatly I want to add them in my code.

            mrjjM 1 Reply Last reply
            0
            • M m1212e

              @Christian-Ehrlicher

              Already did that, but thanks. Unfortunatly I want to add them in my code.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @m1212e
              Hi
              Just as a note. when i want to insert dynamically into a Designer created
              ui, i often just add some test widgets and then go to the generated
              code (in the setupUI function) and see how its inserted. This is especially useful for complex layouts.

              M 1 Reply Last reply
              3
              • mrjjM mrjj

                @m1212e
                Hi
                Just as a note. when i want to insert dynamically into a Designer created
                ui, i often just add some test widgets and then go to the generated
                code (in the setupUI function) and see how its inserted. This is especially useful for complex layouts.

                M Offline
                M Offline
                m1212e
                wrote on last edited by
                #8

                @mrjj
                That's a good idea, thanks. Is there any way to edit the auto generated code?

                jsulmJ mrjjM 2 Replies Last reply
                0
                • M m1212e

                  @mrjj
                  That's a good idea, thanks. Is there any way to edit the auto generated code?

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @m1212e said in Adding a custom widget into an existing layout.:

                  Is there any way to edit the auto generated code?

                  You should not as next time you build your project auto generated code will be overwritten :-)

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  M 1 Reply Last reply
                  3
                  • jsulmJ jsulm

                    @m1212e said in Adding a custom widget into an existing layout.:

                    Is there any way to edit the auto generated code?

                    You should not as next time you build your project auto generated code will be overwritten :-)

                    M Offline
                    M Offline
                    m1212e
                    wrote on last edited by
                    #10

                    @jsulm
                    Well, I expected that, probably I'm better off just outsourcing that into my own files.
                    Thanks for the help guys!

                    1 Reply Last reply
                    0
                    • M m1212e

                      @mrjj
                      That's a good idea, thanks. Is there any way to edit the auto generated code?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @m1212e said in Adding a custom widget into an existing layout.:

                      That's a good idea, thanks. Is there any way to edit the auto generated code?

                      Hi
                      You must copy the code and make it your own.
                      But its very handy to visually build something and then get the code to create it dynamically.

                      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