I would like to create QPushButton
with QIcon
left align (not to the center as default) and text center align. I don't want to use a style sheet. I know that might be possibly using QPainter
but I wasn't able to do it. I had little clue and tried this code:
void MyPushButton::paintEvent(QPaintEvent *)
{
QStylePainter painter(this);
QStyleOptionButton opt;
initStyleOption(&opt);
painter.drawItemPixmap(opt.rect, Qt::AlignLeft, opt.icon);
painter.drawItemText(opt.rect, Qt::AlignCenter, palette(), 1, opt.text);
painter.drawPrimitive(QStyle::PE_PanelButtonCommand, opt);
}
which produces this error message
no matching function for call to 'QStylePainter::drawItemPixmap(QRect&, Qt::AlignmentFlag, QIcon&)' painter.drawItemPixmap(opt.rect, Qt::AlignCenter, opt.icon);
What's wrong with code above?