Issue connecting member function to signal
Solved
General and Desktop
-
I'm having a problem with connecting a custom button class, which inherits from QPushButton.
I want to connect the clicked() signal, (which should be emitted on click, since the parent is QPushButton) to a member function of the class. I've had success with implementing the mousePressEvent function, inside the class.
#include "looperbutton.h" #include <QtGui> #include <QApplication> LooperButton::LooperButton(QWidget *parent) : QPushButton(parent) { this->state = 0; connect(this, SIGNAL(clicked()), this, SLOT(clickedButton())); setFixedSize(100,100); } void LooperButton::clickedButton() { QApplication::beep(); setText("clicked"); } void LooperButton::mousePressEvent(QMouseEvent *e) { //This works }
for completion, here is the header:
#ifndef LOOPERBUTTON_H #define LOOPERBUTTON_H #include <QPushButton> class LooperButton : public QPushButton { Q_OBJECT protected: void enterEvent(QEvent *event); void leaveEvent(QEvent *event); void mousePressEvent(QMouseEvent *event); void mouseReleaseEvent(QMouseEvent *event); private slots: void clickedButton(); private: int state; public: LooperButton(QWidget *parent = 0); ~LooperButton(); }; #endif // LOOPERBUTTON_H
Any suggestions?