QT QPushButton带有图标和重叠的居中文本

Mik*_*ike 5 qt image button centering

我最近参加了Qt编程,并希望将我的应用程序移植到Qt.

我正在摆弄QPushButtons并且我设法在按钮中显示图像并将一些文本设置到按钮,但无论我做什么,无论有没有设计师,我都有同样的问题,文本对齐到图标而不是覆盖图标.

addButton = new QPushButton();
addButton->setIcon(QIcon(":/AddButton.png"));
addButton->setText(tr("+"));
addButton->setFlat(true);
addButton->setIconSize(QSize(100,90));
Run Code Online (Sandbox Code Playgroud)

我错过了什么?

我知道有toolButton但它似乎没有"平面"属性.

有什么好主意吗?

非常感谢,

麦克风

Dav*_*eer 7

如果您尝试将图像用作背景图像,则可以使用样式表:

addButton->setStyleSheet("background-image: url(:/AddButton.png);"
                         "background-repeat: no-repeat;"
                         "background-position: center center");
Run Code Online (Sandbox Code Playgroud)

您只需要确保按钮的大小至少与图像一样大.