Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Panel class */
- class HoverableWidget : public QWidget
- {
- Q_OBJECT
- public:
- HoverableWidget(qint32 min, qint32 max) :
- minsize(min), maxsize(max)
- {
- this->setProperty("hover", "neutral");
- this->setMinimumWidth(minsize);
- this->setMaximumWidth(minsize);
- this->style()->unpolish(this);
- this->style()->polish(this);
- this->update();
- hold = false;
- }
- public slots:
- void holdpanel () { hold = true; }
- void releasepanel() { hold = false;}
- void closepanel () { leaveEvent(NULL); }
- public:
- void enterEvent(QEvent *)
- {
- if (!hold)
- {
- this->setProperty("hover", "hovered");
- this->setMinimumWidth(maxsize);
- this->setMaximumWidth(maxsize);
- this->style()->unpolish(this);
- this->style()->polish(this);
- this->update();
- }
- }
- void leaveEvent(QEvent *)
- {
- if (!hold)
- {
- this->setProperty("hover", "neutral");
- this->setMinimumWidth(minsize);
- this->setMaximumWidth(minsize);
- this->style()->unpolish(this);
- this->style()->polish(this);
- this->update();
- }
- }
- void paintEvent(QPaintEvent *)
- {
- QStyleOption o;
- o.initFrom(this);
- QPainter p(this);
- style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
- }
- private:
- qint32 minsize;
- qint32 maxsize;
- bool hold;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement