PDA

View Full Version : Subclassing a QPushButton



Rajeshkhan
3rd October 2015, 23:18
I subclassed a QPushButton and in the constructor I changed the text of QPushButton however the text does not change in the actual button any suggestions on why the text is not changing ?


#ifndef QCUSTOMPUSHBUTTON
#define QCUSTOMPUSHBUTTON


#include "QObject"
#include "QPushButton"

class QCustomPushBtton : public QPushButton
{
Q_OBJECT

public:
QCustomPushBtton(QWidget *parent=0):QPushButton(parent)
{
this->setText("testing123");
}

signals:
void DoubleClick();

protected:
virtual void mouseDoubleClickEvent(QMouseEvent *) override
{
emit DoubleClick();
}
};


#endif // QCUSTOMPUSHBUTTON

anda_skoa
4th October 2015, 10:43
Do you set text anywhere else?
Have you confirmed that you are creating instances of your button?

While that should not make any difference, you can also pass the text to the base class's constructor:


QCustomPushBtton(QWidget *parent=0):QPushButton("testing123", parent)


Cheers,
_