QPushButton问题

时间:2010-10-05 09:45:04

标签: qt qt4 stylesheet

我使用以下代码创建按钮。它工作正常。但我在左角有一个黄色矩形。为什么?请帮我。提前谢谢,

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

1 个答案:

答案 0 :(得分:3)

我很确定问题不在你发布的代码中(除非cjhuitt提到,它在背景图片中)。我抓住了谷歌的一个简单的背景,并尝试了以下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_())

它产生的按钮没有你在那里显示的奇怪的小黄色框。