QPushButton 问题

发布于 2024-09-26 00:01:17 字数 947 浏览 2 评论 0原文

我正在使用以下代码来创建按钮。它运行良好。但我在左上角看到了黄色矩形。为什么?请帮我。提前致谢,

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

I am using the following code for create a button. It is working fine. but I got the yellow rectangle at the left corner. Why? Please help me. Thanks in advance,

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

末が日狂欢 2024-10-03 00:01:17

我相当确定问题不在您发布的代码中(除非,正如 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_())

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

I'm fairly sure the problem is not in the code you posted (unless, as cjhuitt mentions, it's in the background image). I snagged a simple background png off of google and tried the following 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_())

It produces the button without the odd little yellow box you're showing there.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文