public:
typedef enum States
{
eStateNormal,
eStatePressed,
eStateHovered,
eStateDisabled
} States;
States m_ButtonState;
m_ButtonState = eStateNormal;
}
protected:
if (event->button() == Qt::LeftButton) {
m_ButtonState = eStatePressed;
}
}
if(event->buttons() & Qt::LeftButton) {
m_ButtonState = eStateHovered;
}
}
if(event->buttons() && m_ButtonState == eStatePressed){
m_ButtonState = eStateNormal;
}
}
QRegion r2
(QRect(200,
70,
90,
30));
// r2: rectangular region QRegion r3
= r1.
intersected(r2
);
// r3: intersection
switch( m_ButtonState ){
case eStateNormal:
qpx.
load(QString("JoinNormal.jpg"));
break;
case eStatePressed:
qpx.
load(QString("JoinPressed.jpg"));
break;
case eStateHovered:
qpx.
load(QString("JoinHover.jpg"));
break;
case eStateDisabled:
qpx.
load(QString("JoinNormal.jpg"));
break;
}
QRectF target
(10.0,
20.0,
80.0,
60.0);
QRectF source
(0.0,
0.0,
70.0,
40.0);
painter.drawPixmap(target, qpx, source);
painter.setClipping(true);
painter.setClipRegion(r1);
//QBrush brush(QColor(255,0,0,255));
//painter.setBackground(brush);
//update();
}
};
class QEllipseButton : public QAbstractButton {
public:
typedef enum States
{
eStateNormal,
eStatePressed,
eStateHovered,
eStateDisabled
} States;
States m_ButtonState;
QEllipseButton(QWidget * parent = 0): QAbstractButton(parent){
m_ButtonState = eStateNormal;
}
protected:
void mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton) {
m_ButtonState = eStatePressed;
}
}
void mouseMoveEvent(QMouseEvent *event){
if(event->buttons() & Qt::LeftButton) {
m_ButtonState = eStateHovered;
}
}
void mouseReleaseEvent(QMouseEvent *event){
if(event->buttons() && m_ButtonState == eStatePressed){
m_ButtonState = eStateNormal;
}
}
void paintEvent ( QPaintEvent * event ){
QRegion r1(QRect(200, 50, 500, 400), // r1: elliptic region
QRegion::Ellipse);
QRegion r2(QRect(200, 70, 90, 30)); // r2: rectangular region
QRegion r3 = r1.intersected(r2); // r3: intersection
QPainter painter(this);
QPixmap qpx;
switch( m_ButtonState ){
case eStateNormal:
qpx.load(QString("JoinNormal.jpg"));
break;
case eStatePressed:
qpx.load(QString("JoinPressed.jpg"));
break;
case eStateHovered:
qpx.load(QString("JoinHover.jpg"));
break;
case eStateDisabled:
qpx.load(QString("JoinNormal.jpg"));
break;
}
QRectF target(10.0, 20.0, 80.0, 60.0);
QRectF source(0.0, 0.0, 70.0, 40.0);
painter.drawPixmap(target, qpx, source);
painter.setClipping(true);
painter.setClipRegion(r1);
//QBrush brush(QColor(255,0,0,255));
//painter.setBackground(brush);
//update();
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks