5 #include <QStyleOptionFocusRect>
6 #include <QStylePainter>
19 : QAbstractButton(parent)
21 setCursor(Qt::ArrowCursor);
22 setFocusPolicy(Qt::NoFocus);
34 #if QT_VERSION >= 0x050100
35 const qreal pixmapRatio = m_pixmap.devicePixelRatio();
37 const qreal pixmapRatio = 1.0;
39 return QSize(m_pixmap.width() / pixmapRatio, m_pixmap.height() / pixmapRatio);
44 #if QT_VERSION >= 0x050100
45 const qreal pixmapRatio = m_pixmap.devicePixelRatio();
47 const qreal pixmapRatio = 1.0;
49 QStylePainter painter(
this);
50 QRect pixmapRect = QRect(0, 0, m_pixmap.width() / pixmapRatio, m_pixmap.height() / pixmapRatio);
51 pixmapRect.moveCenter(rect().center());
52 painter.drawPixmap(pixmapRect, m_pixmap);
54 QStyleOptionFocusRect focusOption;
55 focusOption.initFrom(
this);
56 focusOption.rect = pixmapRect;
58 focusOption.rect.adjust(-4, -4, 4, 4);
59 painter.drawControl(QStyle::CE_FocusFrame, focusOption);
61 painter.drawPrimitive(QStyle::PE_FrameFocusRect, focusOption);
68 QAbstractButton::keyPressEvent(event);
69 if (!event->modifiers() && (
event->key() == Qt::Key_Enter ||
event->key() == Qt::Key_Return)) {
77 QAbstractButton::keyReleaseEvent(event);