Flat QPushButtons
have no indication of mouse hovering. Is there a way to set the styling for the flat button hover state so that it matches the style of the normal button hover state (or something similar)?
I don't want to use style sheets if it means deviating away from the default look or having to design the button styles from scratch.
One way of doing it is deriving QPushButton
:
pushbutton.h:
#ifndef PUSHBUTTON_H
#define PUSHBUTTON_H
#include <QPushButton>
class PushButton : public QPushButton
{
Q_OBJECT
public:
explicit PushButton(QWidget *parent = 0);
protected:
bool event(QEvent * event);
};
#endif // PUSHBUTTON_H
pushbutton.cpp:
#include "pushbutton.h"
#include <QEvent>
PushButton::PushButton(QWidget *parent) :
QPushButton(parent)
{
setFlat(true);
}
bool PushButton::event(QEvent *event)
{
if(event->type() == QEvent::HoverEnter)
{
setFlat(false);
}
if(event->type() == QEvent::HoverLeave)
{
setFlat(true);
}
return QPushButton::event(event);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With