diff --git a/components/iconbutton.cpp b/components/iconbutton.cpp index 1c29b32..a7e37ab 100644 --- a/components/iconbutton.cpp +++ b/components/iconbutton.cpp @@ -1,7 +1,5 @@ -#include -#include -#include #include +#include #include #include "iconbutton.h" #include "../lib/rippleoverlay.h" @@ -19,8 +17,6 @@ IconButton::IconButton(const QIcon &icon, QWidget *parent) setSizePolicy(policy); setGeometryWidget(this); - - setStyle(&Style::instance()); } IconButton::~IconButton() @@ -29,13 +25,7 @@ IconButton::~IconButton() QSize IconButton::sizeHint() const { - QStyleOptionButton option(getStyleOption()); - - int w = option.iconSize.width() + 4; - int h = option.iconSize.height(); - - return (style()->sizeFromContents(QStyle::CT_PushButton, &option, QSize(w, h), this). - expandedTo(QApplication::globalStrut())); + return iconSize(); } void IconButton::setGeometryWidget(QWidget *widget) @@ -52,9 +42,10 @@ void IconButton::paintEvent(QPaintEvent *event) { Q_UNUSED(event) - QStylePainter painter(this); - QStyleOptionButton option(getStyleOption()); - painter.drawControl(QStyle::CE_PushButton, option); + QPainter painter(this); + const QSize &size = iconSize(); + QPoint pos(width()/2-size.width()/2, height()/2-size.height()/2); + icon().paint(&painter, QRect(pos, size)); } void IconButton::mousePressEvent(QMouseEvent *event) @@ -87,18 +78,6 @@ bool IconButton::eventFilter(QObject *obj, QEvent *event) return QAbstractButton::eventFilter(obj, event); } -QStyleOptionButton IconButton::getStyleOption() const -{ - QStyleOptionButton option; - option.initFrom(this); - option.features = QStyleOptionButton::Flat; - if (isChecked()) - option.state |= QStyle::State_On; - option.icon = icon(); - option.iconSize = iconSize(); - return option; -} - void IconButton::updateOverlayGeometry() { if (!_overlay || !_geometryWidget) diff --git a/components/iconbutton.h b/components/iconbutton.h index f037000..89419be 100644 --- a/components/iconbutton.h +++ b/components/iconbutton.h @@ -2,7 +2,6 @@ #define ICONBUTTON_H #include -#include class RippleOverlay; @@ -23,8 +22,6 @@ protected: bool event(QEvent *event) Q_DECL_OVERRIDE; bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE; - QStyleOptionButton getStyleOption() const; - private: void updateOverlayGeometry(); diff --git a/examples/iconbuttonexamples.cpp b/examples/iconbuttonexamples.cpp index e5957c6..6fbf923 100644 --- a/examples/iconbuttonexamples.cpp +++ b/examples/iconbuttonexamples.cpp @@ -22,8 +22,6 @@ IconButtonExamples::IconButtonExamples(QWidget *parent) ); frame->setWidget(view); - iconButton->setMinimumSize(50, 50); - layout->addWidget(frame); } { @@ -40,7 +38,21 @@ IconButtonExamples::IconButtonExamples(QWidget *parent) ); frame->setWidget(view); - iconButton->setMinimumSize(50, 50); + layout->addWidget(frame); + } + { + IconButton *iconButton = new IconButton(QIcon("../qt-material-widgets/face.svg")); + iconButton->setIconSize(QSize(128, 128)); + + ExampleView *view = new ExampleView; + view->setWidget(iconButton); + + Frame *frame = new Frame; + frame->setCodeSnippet( + "IconButton *iconButton = new IconButton(QIcon(\"face.svg\"));\n" + "iconButton->setIconSize(QSize(128, 128));\n" + ); + frame->setWidget(view); layout->addWidget(frame); }