Advertisement
Guest User

Panel

a guest
Dec 22nd, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. /* Panel class */
  2. class HoverableWidget : public QWidget
  3. {
  4.     Q_OBJECT
  5.  
  6. public:
  7.     HoverableWidget(qint32 min, qint32 max) :
  8.         minsize(min), maxsize(max)
  9.     {
  10.         this->setProperty("hover", "neutral");
  11.  
  12.         this->setMinimumWidth(minsize);
  13.         this->setMaximumWidth(minsize);
  14.  
  15.         this->style()->unpolish(this);
  16.         this->style()->polish(this);
  17.         this->update();
  18.  
  19.         hold = false;
  20.     }
  21.  
  22. public slots:
  23.     void holdpanel   () { hold = true; }
  24.     void releasepanel() { hold = false;}
  25.     void closepanel  () { leaveEvent(NULL); }
  26.  
  27. public:
  28.     void enterEvent(QEvent *)
  29.     {
  30.         if (!hold)
  31.         {
  32.             this->setProperty("hover", "hovered");
  33.  
  34.             this->setMinimumWidth(maxsize);
  35.             this->setMaximumWidth(maxsize);
  36.  
  37.             this->style()->unpolish(this);
  38.             this->style()->polish(this);
  39.             this->update();
  40.         }
  41.     }
  42.     void leaveEvent(QEvent *)
  43.     {
  44.         if (!hold)
  45.         {
  46.             this->setProperty("hover", "neutral");
  47.  
  48.             this->setMinimumWidth(minsize);
  49.             this->setMaximumWidth(minsize);
  50.  
  51.             this->style()->unpolish(this);
  52.             this->style()->polish(this);
  53.             this->update();
  54.         }
  55.     }
  56.     void paintEvent(QPaintEvent *)
  57.     {
  58.         QStyleOption o;
  59.         o.initFrom(this);
  60.         QPainter p(this);
  61.         style()->drawPrimitive(QStyle::PE_Widget, &o, &p, this);
  62.     }
  63.  
  64. private:
  65.     qint32  minsize;
  66.     qint32  maxsize;
  67.     bool    hold;
  68. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement