Subclassing a widget created in Qt Designer
I have a QLabel within my Qt Designer-created MainWindow.
However, I would like to add mouse tracking to this QLabel by subclassing QLabel and creating a new class called QLabelWithMouseTracking which will contains re-implementations of the appropriate protected functions: mousePressEvent(), mouseReleaseEvent() etc.
My question is:
How do I perform the subclassing and create a new class given that this QLabel is already created and initialized in the Designer UI header file?
Also, I'm using the multi-inheritance approach. i.e.
Code:
#include "ui_MainWindow.h"
class MainWindow
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
};
etc.
Thanks in advance to anyone who can steer me in the right direction! :)
Re: Subclassing a widget created in Qt Designer
Code your derived class. Use the promotion feature in Designer to make the existing label an instance of your sub-class. The promotion dialog can be found on the right-click context menu in Designer.
Re: Subclassing a widget created in Qt Designer
Quote:
Originally Posted by
ChrisW67
Code your derived class. Use the promotion feature in Designer to make the existing label an instance of your sub-class. The promotion dialog can be found on the right-click context menu in Designer.
Works perfectly! Thanks so much for your help! ;)