1
我正在嘗試在我的項目中創建一個QPushButton
,以便文本顯示在自定義按鈕圖像或圖標的頂部。 我嘗試以下方法:如何用圖標上顯示的文本創建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'後面有''''。 – hank