
Originally Posted by
fily_love
i also want the text's color was blue
It will definitely break Maemo styles, but:
Code:
#ifndef COLOUREDBUTTON_H
#define COLOUREDBUTTON_H
#include <QMaemo5ValueButton>
class ColouredButton : public QMaemo5ValueButton
{
Q_OBJECT
public:
explicit ColouredButton(QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
};
#endif //COLOUREDBUTTON_H
Code:
#include <QStylePainter>
#include <QStyleOptionMaemo5ValueButton>
#include "colouredbutton.h"
ColouredButton::ColouredButton(QWidget *parent) : QMaemo5ValueButton(parent)
{
}
void ColouredButton::paintEvent(QPaintEvent *)
{
ValueLayout layout = valueLayout();
QStylePainter p(this);
QStyleOptionButton button;
initStyleOption(&button);
QStyleOptionMaemo5ValueButton option;
initStyleOption(&option);
option.value = valueText();
option.styles = (layout == ValueBesideText) ? QStyleOptionMaemo5ValueButton::ValueBesideText
: QStyleOptionMaemo5ValueButton::ValueUnderText;
option.styles |= QStyleOptionMaemo5ValueButton::PickButton;
if (layout == ValueUnderTextCentered)
option.styles |= QStyleOptionMaemo5ValueButton::Centered;
p.drawControl(QStyle::CE_PushButtonBevel, button);
option.rect = style()->subElementRect(QStyle::SE_PushButtonContents, &button, this);
p.drawControl(QStyle::CE_PushButtonLabel, option);
}