[SOLVED] Inheritance of base class with user interface



  • I am having a little trouble grasping how to use inheritance of a super class with a user interface.

    I have a base QWidget class (with a designer file .ui) that has a table and a couple other objects. I would like to extend this class into different two different sub classes that will populate the list widget with different custom cells.

    For example, my widget is implemented as an animated sliding widget. When the user swipes from the right side of the screen to the center, the widget slides out from the side, likewise with the left side of the screen. I want each of the two widgets to have the same base class, but different cell types.

    @
    #include <QWidget>

    // sliding list ui class
    namespace Ui {
    class SlidingList;
    }

    // sliding list class
    class SlidingList : public QWidget
    {
    Q_OBJECT

    public:
    SlidingList(QWidget *parent = 0);
    virtual ~SlidingList();

    private:
    Ui::SlidingList *ui;
    };
    @

    How would I create class SlidingListSubclass to be able to access the ui? Is is valid to move the ui as protected so it can be accessible from the subclass? Or is there a better way to do this.

    @
    #include <SlidingList>

    // sliding list class
    class SlidingListSubclass : public SlidingList
    {
    Q_OBJECT

    public:
    SlidingListSubclass(QWidget *parent = 0);
    virtual ~SlidingListSubclass();

    private:
    // generate user interface as well?
    // how do ui link the two?
    }
    @

    Thank you!

    Edit: I just was missing a step by including the ui header file generated from QMake in my implementation file. After moving the ui pointer as protected, everything worked as expected.


  • Lifetime Qt Champion

    Hi,

    Making it protected is reasonable or you would need to provide getters for each element you want to access.


Log in to reply
 

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