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 design custom widget in Designer
QtWS25 Last Chance

How to design custom widget in Designer

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 3.2k 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.
  • H Offline
    H Offline
    harshilsharma63
    wrote on 18 Jul 2014, 04:58 last edited by
    #1

    Hi. I want to create a custom widget to be used in a Qt GUI project. However, I do not want to manually code a GUI. What I want to do is create the UI of the widget in Designer, define the signals and slots and get a .h and .cpp file for the widget which I can then promote the other widgets to. I do not know how to obtain the .h and .cpp file for UI designed in Designer and search on Internet didn't revel much steps.

    Please provide the stems for accomplishing this task.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      IamSumit
      wrote on 18 Jul 2014, 05:31 last edited by
      #2

      Hii,

      "Here":http://lmgtfy.com/?q=Qt_Designer_Tutorial_Part_1_YouTube_2#

      {Edited}

      Be Cute

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dheerendra
        Qt Champions 2022
        wrote on 18 Jul 2014, 06:04 last edited by
        #3

        Can you look at Assistant for "Creating Custom Widgets for Designer". This will surely help you. I know you don't want to code.

        Designer creates the *.h file called ui_<yourname>.h file. You can take this file and split the file as .h and .cpp.

        Now you can tweak the process of doing the same.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        0
        • H Offline
          H Offline
          harshilsharma63
          wrote on 18 Jul 2014, 07:30 last edited by
          #4

          I generated the header file from Qt Designer but it has this #include "qframe.h" that Creator is unable to find. WHat to do about this?

          1 Reply Last reply
          0
          • H Offline
            H Offline
            harshilsharma63
            wrote on 18 Jul 2014, 09:44 last edited by
            #5

            [quote author="Dheerendra" date="1405663472"]Can you look at Assistant for "Creating Custom Widgets for Designer". This will surely help you. I know you don't want to code.

            Designer creates the *.h file called ui_<yourname>.h file. You can take this file and split the file as .h and .cpp.

            Now you can tweak the process of doing the same.
            [/quote]

            I generated the header file from Qt Designer but it has this #include “qframe.h” that Creator is unable to find. WHat to do about this?

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dheerendra
              Qt Champions 2022
              wrote on 18 Jul 2014, 11:37 last edited by
              #6

              Are able to create the project with designer form and run your program ? If yes, you should find out the path in which this file exist and give the appropriate include dir path for the project.

              I used Qt 5.2.x and I designed form with QFrame etc. I did not see the any qframe.h included. May be it is specific to your design.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • H Offline
                H Offline
                harshilsharma63
                wrote on 18 Jul 2014, 15:44 last edited by
                #7

                [quote author="Dheerendra" date="1405683430"]Are able to create the project with designer form and run your program ? If yes, you should find out the path in which this file exist and give the appropriate include dir path for the project.

                I used Qt 5.2.x and I designed form with QFrame etc. I did not see the any qframe.h included. May be it is specific to your design.[/quote]

                What I want is a custom widget with some lables, line edits and few other components in it. This component will be used as a UI element in another Qt project. So I create a Frame in designer and included all components I want in this widget. Now I want this Frame with all the widgets it contain to be available as a separate file so that I can simply promote a Widget to this frame (containing other components) in the main project.

                Shouldn't I be creating a frame in designer is this task to be done in some other way?

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on 19 Jul 2014, 06:27 last edited by
                  #8

                  No it is right. QFrame is derived from QWidget. It should be fine. I tried to create very similar UI using the designer. My *.h files did not had any qfame.h file. Can you check with small example first ? Which version of Qt you are using ?

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    harshilsharma63
                    wrote on 19 Jul 2014, 07:15 last edited by
                    #9

                    [quote author="Dheerendra" date="1405751248"]No it is right. QFrame is derived from QWidget. It should be fine. I tried to create very similar UI using the designer. My *.h files did not had any qfame.h file. Can you check with small example first ? Which version of Qt you are using ?[/quote]

                    I'm using Qt 5.3.1

                    I tried creating a small sample in this way-

                    1. Start Designer -> New -> Widgets -> QFrame -> create

                    2. Added a few components like sliders etc.

                    3. Form -> view code -> save the header file (ui_sadsad.h)

                    4. Created a new Qt Widgets project in Creator and added the header file obtained from Designer to this project.

                    5. In the auto-created ui file, added a Widget and promoted it to Ui_Sadsad.

                    6. Built and got error in ui_mainwondow.h-

                    @/********************************************************************************
                    ** Form generated from reading UI file 'mainwindow.ui'
                    **
                    ** Created by: Qt User Interface Compiler version 5.3.1
                    **
                    ** WARNING! All changes made in this file will be lost when recompiling UI file!
                    ********************************************************************************/

                    #ifndef UI_MAINWINDOW_H
                    #define UI_MAINWINDOW_H

                    #include <QtCore/QVariant>
                    #include <QtWidgets/QAction>
                    #include <QtWidgets/QApplication>
                    #include <QtWidgets/QButtonGroup>
                    #include <QtWidgets/QHeaderView>
                    #include <QtWidgets/QMainWindow>
                    #include <QtWidgets/QMenuBar>
                    #include <QtWidgets/QStatusBar>
                    #include <QtWidgets/QToolBar>
                    #include <QtWidgets/QWidget>
                    #include "ui_frame.h" <-------------------------------------------- this is the problem

                    QT_BEGIN_NAMESPACE

                    class Ui_MainWindow
                    {
                    public:
                    QWidget *centralWidget;
                    Ui_Frame *widget;
                    QMenuBar *menuBar;
                    QToolBar *mainToolBar;
                    QStatusBar *statusBar;

                    void setupUi(QMainWindow *MainWindow)
                    {
                        if (MainWindow->objectName().isEmpty())
                            MainWindow->setObjectName(QStringLiteral("MainWindow"));
                        MainWindow->resize(400, 300);
                        centralWidget = new QWidget(MainWindow);
                        centralWidget->setObjectName(QStringLiteral("centralWidget"));
                        widget = new Ui_Frame(centralWidget);
                        widget->setObjectName(QStringLiteral("widget"));
                        widget->setGeometry(QRect(60, 50, 120, 80));
                        MainWindow->setCentralWidget(centralWidget);
                        menuBar = new QMenuBar(MainWindow);
                        menuBar->setObjectName(QStringLiteral("menuBar"));
                        menuBar->setGeometry(QRect(0, 0, 400, 21));
                        MainWindow->setMenuBar(menuBar);
                        mainToolBar = new QToolBar(MainWindow);
                        mainToolBar->setObjectName(QStringLiteral("mainToolBar"));
                        MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
                        statusBar = new QStatusBar(MainWindow);
                        statusBar->setObjectName(QStringLiteral("statusBar"));
                        MainWindow->setStatusBar(statusBar);
                    
                        retranslateUi(MainWindow);
                    
                        QMetaObject::connectSlotsByName(MainWindow);
                    } // setupUi
                    
                    void retranslateUi(QMainWindow *MainWindow)
                    {
                        MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0));
                    } // retranslateUi
                    

                    };

                    namespace Ui {
                    class MainWindow: public Ui_MainWindow {};
                    } // namespace Ui

                    QT_END_NAMESPACE

                    #endif // UI_MAINWINDOW_H
                    @

                    I think stem 5 onwards I'm doinf it wrong.

                    1 Reply Last reply
                    0
                    • H Offline
                      H Offline
                      harshilsharma63
                      wrote on 19 Jul 2014, 07:16 last edited by
                      #10

                      Anyways, can you point me to the correct steps?

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        dheerendra
                        Qt Champions 2022
                        wrote on 19 Jul 2014, 07:37 last edited by
                        #11

                        oh!!!. ui_frame.h file generated file. Your designer class name frame. Hence it is generating ui_frame.h file. You can remove this and do what split you want to for .h and .cpp files.

                        Dheerendra
                        @Community Service
                        Certified Qt Specialist
                        http://www.pthinks.com

                        1 Reply Last reply
                        0
                        • H Offline
                          H Offline
                          harshilsharma63
                          wrote on 19 Jul 2014, 13:49 last edited by
                          #12

                          [quote author="Dheerendra" date="1405755474"]oh!!!. ui_frame.h file generated file. Your designer class name frame. Hence it is generating ui_frame.h file. You can remove this and do what split you want to for .h and .cpp files.[/quote]

                          But then you have error in every line that refers to Ui_Frame like line 30 and 42. It's really irritating me.

                          1 Reply Last reply
                          0

                          3/12

                          18 Jul 2014, 06:04

                          9 unread
                          • Login

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