【发布时间】:2016-04-21 22:44:51
【问题描述】:
我正在尝试在我的项目中创建一个QPushButton,以便文本显示在自定义按钮图像或图标的顶部。
我尝试了以下方法:
imagePath = path;
QPixmap pixmap(imagePath);
QIcon ButtonIcon(pixmap);
button->setIcon(ButtonIcon);
button->setIconSize(pixmap.rect().size());
button->setGeometry(0,0,height,width);
button->setStyleSheet(
"background-color: gray;"
"border: 1px solid black;"
"border-radius: "+QString::number(radius)+"px;"
"color: lightGray; "
"font-size: 25px;"
);
当我在这里尝试使用setText 时,它首先显示图标,然后在其右侧显示文本。我希望文本显示在图标顶部。
我也尝试了网上找到的以下方法:
imagePath = path;
button->setGeometry(0,0,height,width);
button->setStyleSheet("background-image: url(:/images/images/2adjacentTracksButton.png));"
"background-position: center center");
这个不接受我的 url 路径,因此没有在按钮上显示我需要的图像。
我该如何解决这个问题?
【问题讨论】:
-
在 QSS 表达式中的 '2adjacentTracksButton.png' 之后有额外的 ')'。
标签: c++ qt qpushbutton