2010-10-05 52 views
2

我正在使用以下代碼創建按鈕。它工作正常。但是我在左角找到了黃色的矩形。爲什麼?請幫幫我。在此先感謝,QPushButton問題

backButton = new QPushButton(tr("Back")); 
     connect(backButton, SIGNAL(clicked()), this, SLOT(showSearchResultPage())); 
     backButton->setStyleSheet(
      "background-image: url(/Users/aspire/IPhone Development/background_wood_Default.png);" 
      "border-style: outset;" 
      "border-width: 2px;" 
      "border-radius: 10px;" 
      "border-color: beige;" 
      "font: bold 16px;" 
      "color:black;" 
      "min-width: 10em;" 
      "min-height: 0.75em;" 
      " margin: 0 1px 0 1px;" 
      "color:rgb(255,246,143);" 
      "padding: 6px;" 
     ); 



QGridLayout *layout = new QGridLayout(); 
    layout->addWidget(backButton, 1, 0, 1, 1); 
    layout->addWidget(detailView, 2, 0, 1, 1); 

alt text

+0

把按鈕的快照 – Naruto 2010-10-05 13:00:06

+0

只是爲了仔細檢查:你確定矩形不在你的背景圖片? – 2010-10-05 15:05:10

+0

在高倍率下,黃線跨越底部邊界,所以我不認爲它在背景圖像中。正如Jkerian所說,問題在別處:)我猜想另一個小部件是按鈕的父元素,或者按鈕的父元素有一個由按鈕繼承的樣式表(沒有選擇器)。 – 2010-10-05 21:21:43

回答

3

我相當肯定的問題並不在你發佈的代碼(除非像cjhuitt提到,它在背景圖像)。我鉤住了一個簡單的背景PNG關閉谷歌和嘗試了以下的Python:

from PyQt4 import QtCore, QtGui 
import sys 

app = QtGui.QApplication(sys.argv) 

widget = QtGui.QWidget() 

button = QtGui.QPushButton("Back") 

button.setStyleSheet(
     "background-image: url(wood.png);" 
     "border-style: outset;" 
     "border-width: 2px;" 
     "border-radius: 10px;" 
     "border-color: beige;" 
     "font: bold 16px;" 
     "color: black;" 
     "min-width: 10em;" 
     "min-height: 0.75em;" 
     "margin: 0 1px 0 1px;" 
     "color:rgb(255,245,143);" 
     "padding: 6px;" 
     ) 

grid = QtGui.QGridLayout(widget) 
grid.addWidget(button,1,0,1,1) 

widget.show() 

sys.exit(app.exec_()) 

它產生的一個按鈕,你正在展示那裏的奇怪的小黃框。

+0

Thanks.If我使用樣式表按鈕然後只有我有矩形。如果我使用std按鈕風格,那麼我沒有得到這個問題。請幫助我..我用下面的代碼。 secondclsss :: secondclsss(QWidget * parent): QWidget(parent) QPushButton * first = new QPushButton(「first」); first-> setStyleSheet( 「background-color:black;」 ); QGridLayout * d = new QGridLayout(); d-> addWidget(frist,0,0,1,1); setLayout(d);連接(首先,SIGNAL(clicked()),這個,SLOT(first())); } void secondclsss :: first() { this-> hide(); } – Finder 2010-10-06 04:35:04

+0

Python?那是作弊! ;) – mlvljr 2013-06-10 14:20:57