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. Qt Creator (design view) insert a class object onto the form [SOLVED]
QtWS25 Last Chance

Qt Creator (design view) insert a class object onto the form [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 2.9k 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.
  • I Offline
    I Offline
    ion_knight
    wrote on last edited by
    #1

    Currently trying to figure out how to use the .ui form correctly. Currently what I have is a layout class which creates an object called mplayer_wrapper, currently I do all the layout in the layout constructor. However I would like to know how I would insert mplayer_wrapper onto the designer so that I can manage it there.

    Currently I am thinking that I have to use the "Widget" object on the design pane, however not sure how to implement this correctly.

    MainWindow constructor
    @ mplayer_wrapper *wrapper = new mplayer_wrapper(this);
    //ui->widget->setObjectName(wrapper);
    @

    This is the object I wish to display on the form which I currently use by creating a vlayout in the code.

    @vlayout->addWidget(wrapper);@

    If someone could point me to a link or how to actually create this on the ui form I would be very grateful.

    1 Reply Last reply
    0
    • IamSumitI Offline
      IamSumitI Offline
      IamSumit
      wrote on last edited by
      #2

      Hii.
      Do you want to use your mplayer_wrapper class object into designer ?

      Be Cute

      1 Reply Last reply
      0
      • I Offline
        I Offline
        ion_knight
        wrote on last edited by
        #3

        Yea would like to set it's layout via the designer whether that be inserting it into another "pane" which I then control or control the size and position of the object itself. Either way I'll be happy just trying to implement my code in the designer instead.

        Here is the whole constructor layout class which contains all the things I would like to do on the designer instead of in code.
        @ MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);

        QPalette p(palette());
        p.setColor(QPalette::Background, Qt::lightGray);
        this->setAutoFillBackground(true);
        this->setPalette(p);
        this->resize(1000,500);
        this->setWindowTitle(QApplication::translate("toplevel", "CCTV"));
        
        mplayer_wrapper *wrapper = new mplayer_wrapper(this);
        label = new QLabel(this);
        Timer = new QTimer(this);
        
        
        button1 = new QPushButton("Stop State");
        button2 = new QPushButton("Start Stream");
        button3 = new QPushButton("Time");
        vlayout = new QVBoxLayout();
        
        vlayout->addWidget(wrapper);
        vlayout->addWidget(button1);
        vlayout->addWidget(button2);
        vlayout->addWidget(button3);
        vlayout->addWidget(label);
        
        ui->centralWidget->setLayout(vlayout);
        
        connect(button1, &QPushButton::clicked,wrapper,&mplayer_wrapper::stop_mplayer);
        connect(button2, &QPushButton::clicked,wrapper,&mplayer_wrapper::start_mplayer);
        //connect(button3, &QPushButton::clicked,this,   &MainWindow::show_time);
        connect(Timer,&QTimer::timeout,this,&MainWindow::show_time);
        
        //ui->widget->setObjectName(wrapper);
        
        Timer->start();
        

        }
        @

        As you can see I tried to insert wrapper into the "widget" created on the ui form (commented out at the bottom), however that is definitely the incorrect method to insert it inside but really have no clue how I should be doing it.

        1 Reply Last reply
        0
        • IamSumitI Offline
          IamSumitI Offline
          IamSumit
          wrote on last edited by
          #4

          Hiii..
          it is not possible during design time ..if you want to see an object(like wrapper) on your designer and manage it using designer.
          it can be possible via code (during run time).

          Be Cute

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ion_knight
            wrote on last edited by
            #5

            Ok if it's not possible to manipulate the actual object itself on the designer, how would I create a widget/pane on the designer and then place my object (wrapper) into this widget/pane ?

            1 Reply Last reply
            0
            • IamSumitI Offline
              IamSumitI Offline
              IamSumit
              wrote on last edited by
              #6

              tell me what is your wrapper object is it any widget ?

              Be Cute

              1 Reply Last reply
              0
              • I Offline
                I Offline
                ion_knight
                wrote on last edited by
                #7

                Yea it inherits from a QWidget so yes.

                1 Reply Last reply
                0
                • IamSumitI Offline
                  IamSumitI Offline
                  IamSumit
                  wrote on last edited by
                  #8

                  Ok
                  No problem ..

                  then you have to take a normal QWidget having the geometry like wrapper on widget/pane Window .then replace it via coding.

                  NOTE:The best way to do so by coding its provides flexibility.

                  Be Cute

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    ion_knight
                    wrote on last edited by
                    #9

                    Not actually asking to actually replace a widget that is on the form with one that is in my code. All I want to do is insert my QWidget object inside an Widget created on the form so that I can set the design.

                    Anyway what your saying doesn't really help me, as all you have told me is what to do rather than how to do it. Anything will do just need a link to a useful post on it as I know it can be done just no idea how to do it.

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      ion_knight
                      wrote on last edited by
                      #10

                      Ah well figure a way I can do it making as solved.

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        Hi,

                        If I've understood you correctly it looks like the "Creating Custom Widgets for Qt Designer" chapter of Qt's documentation is the place to start

                        Interested in AI ? www.idiap.ch
                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        0
                        • I Offline
                          I Offline
                          ion_knight
                          wrote on last edited by
                          #12

                          Hey SGaist,

                          Gave them a go they work ok but it just doesn't seem right for my application. As all I am wanting to do is create widgets (multiples) inside another widget (which is on the form) so that I can set a fix layout for the widget (the one on the form), so the internal widgets (no matter how many there are) will always keep to the size of "widget".

                          Also what are the overheads in using a custom widget ? Disadvantages etc ?

                          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