
Originally Posted by
Lykurg
Subclass
QPushButton and reimplement the enterEvent where you emit the clicked signal.
Look at the samples of the documentation, there you will find similar problems, where Qt classes where subclassed and event handlers reimplemented. If you have problems, show us what you have tried and we will go on.
Thanks. Here is my code.
custom.h
#ifndef CUSTOM_H
#define CUSTOM_H
#include <QWidget>
#include <QPushButton>
namespace Ui {
class custom;
}
{
Q_OBJECT
public:
explicit Custom
(QWidget *parent
= 0);
~Custom();
void display();
private:
Ui::custom *ui;
public slots:
void display();
};
#endif // CUSTOM_H
#ifndef CUSTOM_H
#define CUSTOM_H
#include <QWidget>
#include <QPushButton>
namespace Ui {
class custom;
}
class Custom : public QPushButton
{
Q_OBJECT
public:
explicit Custom(QWidget *parent = 0);
~Custom();
void enterEvent(QEvent * );
void display();
private:
Ui::custom *ui;
public slots:
void display();
};
#endif // CUSTOM_H
To copy to clipboard, switch view to plain text mode
custom.cpp
#include "custom.h"
#include "ui_custom.h"
#include <QMessageBox>
#include<QPushButton>
ui(new Ui::custom)
{
ui->setupUi(this);
}
void Custom
::enterEvent(QEvent *) {
Q_emit clicked();
}
void Custom::display()
{
msg.setText("CLICKED");
msg.exec();
}
Custom::~Custom()
{
delete ui;
}
#include "custom.h"
#include "ui_custom.h"
#include <QMessageBox>
#include<QPushButton>
Custom::Custom(QWidget *parent) :
QPushButton (parent),
ui(new Ui::custom)
{
ui->setupUi(this);
}
void Custom::enterEvent(QEvent *)
{
Q_emit clicked();
}
void Custom::display()
{
QMessageBox msg;
msg.setText("CLICKED");
msg.exec();
}
Custom::~Custom()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
It works when i click that push button. How do i do that event occurs when cursor comes over that particular push button (but without click)????
Also, i am able to do that message box is displayed when cursor comes over widget, but not over push button.
Where am i wrong??
Bookmarks