implement raised button disabled look

This commit is contained in:
laserpants 2016-05-28 17:08:05 +03:00
parent f541a86301
commit 20db7569f3
3 changed files with 23 additions and 8 deletions

View File

@ -122,6 +122,20 @@ void RaisedButton::setRole(Material::Role role)
update(); update();
} }
bool RaisedButton::event(QEvent *event)
{
Q_D(RaisedButton);
if (QEvent::EnabledChange == event->type()) {
if (isEnabled()) {
d->machine.start();
} else {
d->machine.stop();
}
}
return FlatButton::event(event);
}
void RaisedButton::paintEvent(QPaintEvent *event) void RaisedButton::paintEvent(QPaintEvent *event)
{ {
Q_UNUSED(event) Q_UNUSED(event)
@ -135,13 +149,13 @@ void RaisedButton::paintEvent(QPaintEvent *event)
QBrush brush; QBrush brush;
if (isEnabled()) { brush.setStyle(Qt::SolidPattern);
brush.setStyle(Qt::SolidPattern); brush.setColor(isEnabled()
brush.setColor(palette().color(QPalette::Active, QPalette::Background)); ? palette().color(QPalette::Active, QPalette::Background)
painter.setBrush(brush); : palette().color(QPalette::Disabled, QPalette::Background));
painter.setPen(Qt::NoPen); painter.setBrush(brush);
painter.drawRoundedRect(rect(), 3, 3); painter.setPen(Qt::NoPen);
} painter.drawRoundedRect(rect(), 3, 3);
if (isEnabled()) { if (isEnabled()) {
const qreal hs = static_cast<qreal>(width())*d->delegate->focusHaloSize()/2; const qreal hs = static_cast<qreal>(width())*d->delegate->focusHaloSize()/2;

View File

@ -16,6 +16,7 @@ public:
void setRole(Material::Role role) Q_DECL_OVERRIDE; void setRole(Material::Role role) Q_DECL_OVERRIDE;
protected: protected:
bool event(QEvent *event) Q_DECL_OVERRIDE;
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE; void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
private: private:

View File

@ -13,7 +13,7 @@ RaisedButtonExamples::RaisedButtonExamples(QWidget *parent)
raisedButton->setRole(Material::Primary); raisedButton->setRole(Material::Primary);
raisedButton->setText("Press me!"); raisedButton->setText("Press me!");
raisedButton->setDisabled(true); //raisedButton->setDisabled(true);
//raisedButton->setFixedSize(400, 50); //raisedButton->setFixedSize(400, 50);