How to design custom widget in Designer



  • 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.





  • 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.



  • 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?



  • [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?



  • 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 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?



  • 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 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.



  • Anyways, can you point me to the correct steps?



  • 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 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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.