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. [SOLVED] Adding my own widget to Qt designer generated code
Qt 6.11 is out! See what's new in the release blog

[SOLVED] Adding my own widget to Qt designer generated code

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 1.7k 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.
  • M Offline
    M Offline
    maxg0
    wrote on last edited by
    #1

    I am trying to add a Dial widget that I have designed by inheriting from QWidget to an existing Qt generated code. I am following this post: "Add widgets manually to Qt designer generated code".
    However the instructions in the post work for those simple controls, but they do not seem to work for my own widget, why?
    What do I have to do to add my own widget to a Main window or even better to a Tab within the main window?

    Thanks
    m

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

      Hi,

      Please show us what you tried; it's impossible to say what's wrong otherwise

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

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxg0
        wrote on last edited by
        #3

        Ok, before going into how to add controls to a tab widget within the main window, I will concentrate on the following code:

        #include "boatsimcontrol.h"
        #include "ui_boatsimcontrol.h"
        #include "MyNeedle.h"

        BoatSimControl::BoatSimControl(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::BoatSimControl)
        {
        ui->setupUi(this);

        MyNeedle needle;
        QHBoxLayout *btnLayout = new QHBoxLayout;
        
        btnLayout->addStretch();
        btnLayout->addWidget(&needle);
        
        QVBoxLayout *mainLayout = new QVBoxLayout(this);
        mainLayout->addLayout(btnLayout);
        this->centralWidget()->setLayout(mainLayout);
        

        }

        Unless I am missing out something from the post I mentioned in my first comment, this should allow me to display a MyNeedle into the main window. Am I correct?

        Thanks
        M

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

          No, your object "needle" has been destroyed before you can see it.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxg0
            wrote on last edited by
            #5

            Ops, local variable is destroyed once we get out of the constructor scope. Apologies to the C++ programmer :-). Thanks for spotting this out.

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

              Place [SOLVED] in front of your first post, keeps us from unnecessary reading this post.

              Greetz, Jeroen

              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