Thanks to all for your help.
I didn't get it solved with stylesheets, but I found a solution which works for me:
class SettingsButton : public QPushButton
{
Q_OBJECT
public:
explicit SettingsButton(QWidget *parent = 0);
void setText2(const QString &text1, const QString &text2);
QString getText1();
QString getText2();
signals:
public slots:
protected:
virtual void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE {
QRect rect1(55,0,356,25);
QRect rect2(55,25,356,25);
QFont font;
QPushButton::paintEvent(event); //To draw everything of a normal QPushButton
m_color = QColor(Qt::white); //same as in stylesheet QPushButton (normal)
if( QWidget::hasFocus() ) {
m_color = QColor(Qt::red); //same as in stylesheet QPushButton:focus
}
if( QWidget::underMouse() ) {
m_color = QColor(Qt::blue); //same as in stylesheet QPushButton:hover
}
if( QPushButton::isDown() ) {
m_color = QColor(Qt::green); //same as in stylesheet QPushButton:pressed
}
//Display additional text
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing, true);
painter.setPen(m_color);
font = painter.font();
painter.setFont(QFont(font.family(), font.pointSize(), QFont::Bold));
painter.drawText(rect1, Qt::AlignLeft|Qt::AlignVCenter, firstText);
painter.setFont(QFont(font.family(), font.pointSize(), QFont::Normal));
painter.drawText(rect2, Qt::AlignRight|Qt::AlignVCenter, secondText);
}
private:
QString firstText;
QString secondText;
QColor m_color;
};