4 #include <QStyleOptionFocusRect> 5 #include <QStylePainter> 18 : QAbstractButton(parent)
20 setCursor(Qt::ArrowCursor);
21 setFocusPolicy(Qt::NoFocus);
33 #if QT_VERSION >= 0x050100 34 const qreal pixmapRatio = m_pixmap.devicePixelRatio();
36 const qreal pixmapRatio = 1.0;
38 return QSize(m_pixmap.width() / pixmapRatio, m_pixmap.height() / pixmapRatio);
43 #if QT_VERSION >= 0x050100 44 const qreal pixmapRatio = m_pixmap.devicePixelRatio();
46 const qreal pixmapRatio = 1.0;
48 QStylePainter painter(
this);
49 QRect pixmapRect = QRect(0, 0, m_pixmap.width() / pixmapRatio, m_pixmap.height() / pixmapRatio);
50 pixmapRect.moveCenter(rect().center());
51 painter.drawPixmap(pixmapRect, m_pixmap);
53 QStyleOptionFocusRect focusOption;
54 focusOption.initFrom(
this);
55 focusOption.rect = pixmapRect;
57 focusOption.rect.adjust(-4, -4, 4, 4);
58 painter.drawControl(QStyle::CE_FocusFrame, focusOption);
60 painter.drawPrimitive(QStyle::PE_FrameFocusRect, focusOption);
67 QAbstractButton::keyPressEvent(event);
68 if (!event->modifiers() && (
event->key() == Qt::Key_Enter ||
event->key() == Qt::Key_Return)) {
76 QAbstractButton::keyReleaseEvent(event);