Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to re-use a Widget inside another project - NEWBIE



  • Hi all,
    this is my first post and I'm a ** very newbie ** in Qt programming and not very newbie in general OOP.
    I'm trying to understand how to reuse some widget that I created (in other projects) in new projects.
    I try to explain better.
    I created a widget (with its ui and many files .cpp and .h).
    Now I want to create a mainwindow where put a certain number of these widgets and I hope to see every widget inside my mainwindow in a fixed position.
    Every time that I want to add a new widget, the new position will be near to the previously widget created.
    I want that every widget can be removed using a button on the same widget.

    How can I do this operations?
    Can you suggest some way?
    Sorry if the question is banal but I really don't full understand Qt methods and classes.

    ** Thank you ** in advance for every help you will give me! ;)
    Mik



  • @Miklux

    I'm trying to understand how to reuse some widget that I created (in other projects) in new projects.

    You can simply make new and you can use your own widget. Also check this "Promote widget in Qt Designer"
    Eg: MyWidget * gh = new MyWidget; //you will have copy of MyWidget and can access all the functiosn signals and slots inside it.

    Now I want to create a mainwindow where put a certain number of these widgets and I hope to see every widget inside my mainwindow in a fixed position.Every time that I want to add a new widget, the new position will be near to the previously widget created.

    You can use Layouts to set the position of the widgets basing on your requirement.

    I want that every widget can be removed using a button on the same widget.

    If "MYWidget " derived from the QDialog or something like this, you will have close by default. If not , You can set close button on your MyWidget and add the close functionality to it.



  • @Ni.Sumi

    Great!
    Tomorrow I will try your suggestions and will give you a feedback

    Thank you very much
    Mik


Log in to reply