我正在尝试通过子类化并覆盖paintEvent来自定义QPUshButton。我正在写文本,然后是如下图标:
paintEvent(QPaintEvent *paint)
{
QStyleOption opt;
opt.init(this);
QPainter p(this);
//Draw the base
style()->drawPrimitive(QStyle::PE_Widget, &opt, &p, this);
//Draw the text
style()->drawItemText(&p,this->rect(),Qt::AlignCenter,(this->palette()), true, this->text());
//How do I make the image immediately follow the text
if(!this->icon().isNull())
//Draw the icon at 75% button height
style()->drawItemPixmap(&p, this->rect(),Qt::AlignRight|Qt::AlignVCenter, this->icon().pixmap(this->rect().height() * 0.75));
}
我居中对齐文本,右对齐图标。但是,这会导致文本和图标之间出现间隙。有什么办法让我在文本之后立即绘制图标,而不是对齐?
换句话说,有没有办法获得drawItemText完成的位置?