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. [SOLVED] Inheritance of base class with user interface
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Inheritance of base class with user interface

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.4k Views 1 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.
  • V Offline
    V Offline
    vezprog
    wrote on last edited by
    #1

    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.

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

      Hi,

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

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

      1 Reply Last reply
      0

      • Login

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