[Solved] Construct QPushButton with QIcon alignleft and text center align


you’re getting

this error code error: no matching function for call to ‘QStylePainter::drawItemPixmap(QRect&, Qt::AlignmentFlag, QIcon&)’ painter.drawItemPixmap(opt.rect, Qt::AlignCenter, opt.icon);

because drawItemPixmap draws… a pixmap. Not an icon. So all you need to do is get the icons pixmap using the pixmap() accessor.

change

painter.drawItemPixmap(opt.rect, Qt::AlignLeft, opt.icon);

to

// or whaever size you want
painter.drawItemPixmap(opt.rect, Qt::AlignLeft, opt.icon.pixmap(QSize(16,16))); 

4

solved Construct QPushButton with QIcon alignleft and text center align