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. how to use custom widget with Arguments in QCreator
Forum Updated to NodeBB v4.3 + New Features

how to use custom widget with Arguments in QCreator

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.6k Views 3 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.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on last edited by Qt Enthusiast
    #1

    As I know we can use Promote to feature of QTCreator to add a custom widget in QTCreator ui files. For example the following image https://ibb.co/kyN9cH ,we can see the Promote to feature. I have following three files

    1. samplewidget.ui

    <?xml version="2.0" encoding="UTF-8"?>
    <ui version="4.0">
    <class>SampleWidget</class>
    <widget class="QWidget" name="SampleWidget">
    <property name="geometry">
    <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
    </rect>
    </property>
    <property name="windowTitle">
    <string>SampleWidget</string>
    </property>
    <property name="styleSheet">
    <string notr="true">border-color: rgb(255, 85, 0);</string>
    </property>
    <widget class="QWidget" name="CustomWidget" native="true">
    <property name="geometry">
    <rect>
    <x>170</x>
    <y>90</y>
    <width>120</width>
    <height>80</height>
    </rect>
    </property>
    <property name="styleSheet">
    <string notr="true">background-color: rgb(170, 255, 255);</string>
    </property>
    </widget>
    <widget class="QGroupBox" name="groupBox">
    <property name="geometry">
    <rect>
    <x>160</x>
    <y>70</y>
    <width>241</width>
    <height>141</height>
    </rect>
    </property>
    <property name="title">
    <string>MyBox</string>
    </property>
    </widget>
    </widget>
    <layoutdefault spacing="6" margin="11"/>
    <resources/>
    <connections/>
    </ui>
    2 sampleWidget.cpp

    #include "samplewidget.h"
    #include "ui_samplewidget.h"

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

    SampleWidget::~SampleWidget()
    {
    delete ui;
    }
    3) samplewidget.h

    #include <QWidget>

    namespace Ui {
    class SampleWidget;
    }

    class SampleWidget : public QWidget
    {
    Q_OBJECT

    public:
    explicit SampleWidget(QWidget *parent = 0);
    

    ~SampleWidget();

    private:
    Ui::SampleWidget *ui;
    };
    Now I want to promote CustomWidget to following myWidget widget

    class myWidget: public QObject {
    Q_OBJECT:
    myWidget((QFrame* frame, QList<QString> = {});
    }
    myWidget::myWidget(QFrame* frame , QList<QString> = {}) {}
    I am not able to do the same . I am looking for some help here

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

      Hi,

      What do you want to do with that list of QString ? (By the way, there's a class called QStringList)

      On a side note, you should have parent as last parameter. It's not mandatory but most if not all Qt users are used to have it like that especially since it has usually a default value of nullptr.

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

      Q 1 Reply Last reply
      2
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on last edited by
        #3

        It was legacy code , I will make the changes as per your suggestion an it will great if you can tell how to promote my customWidget in my ui file to this newCustimWidget using Qt Creator or any other smarter way

        class neCustomWidget : public QWidget {
        customWidget(QStringList* QFrame* parent>
        }

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          What do you want to do with that list of QString ? (By the way, there's a class called QStringList)

          On a side note, you should have parent as last parameter. It's not mandatory but most if not all Qt users are used to have it like that especially since it has usually a default value of nullptr.

          Q Offline
          Q Offline
          Qt Enthusiast
          wrote on last edited by
          #4

          @SGaist

          Qt Enthusiast about 3 hours ago
          It was legacy code , I will make the changes as per your suggestion an it will great if you can tell how to promote my customWidget in my ui file to this newCustimWidget using Qt Creator or any other smarter way

          class neCustomWidget : public QWidget {
          customWidget(QStringList* QFrame* parent>
          }

          I am waiting for your help

          kshegunovK 1 Reply Last reply
          0
          • Q Qt Enthusiast

            @SGaist

            Qt Enthusiast about 3 hours ago
            It was legacy code , I will make the changes as per your suggestion an it will great if you can tell how to promote my customWidget in my ui file to this newCustimWidget using Qt Creator or any other smarter way

            class neCustomWidget : public QWidget {
            customWidget(QStringList* QFrame* parent>
            }

            I am waiting for your help

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by
            #5

            @Qt-Enthusiast said in how to use custom widget with Arguments in QCreator:

            I am waiting for your help

            Have some patience.

            how to promote my customWidget in my ui file to this newCustimWidget using Qt Creator or any other smarter way

            Have you taken a look at the manual?

            Read and abide by the Qt Code of Conduct

            1 Reply Last reply
            2

            • Login

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