python - Qt:按钮上没有边框,使其不可点击?

标签 python qt pyside

我正在尝试为按钮设置样式,使其没有边框,但似乎缺少边框会使按钮不可单击。有没有更好的无边框方法?

button = QtGui.QPushButton(todo, self)
button.move(0, i * 32)
button.setFixedSize(200,32)
button.setCheckable(True)
button.setStyleSheet("QPushButton { background: rgb(75, 75, 75); color: rgb(255, 255, 255); text-align: left; font-size: 12pt; border: none;}")

最佳答案

编辑:哎呀,刚刚注意到这是一个关于 Qt/Python(而不是 Qt/C++)的问题,也许我的答案无论如何都有帮助..

刚尝试了一下,对我有用... 这是我使用的代码:

#include <QtGui/QApplication>
#include <QtGui/QPushButton>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QWidget w;
    QPushButton* button = new QPushButton("i am toggleable", &w);
    button->setFixedSize(200,32);
    button->setCheckable(true);
    button->setStyleSheet(
    "QPushButton { \
        background: rgb(75, 75, 75);\
        color: rgb(255, 255, 255);\
        text-align: left;\
        font-size: 12pt;\
        border: none;\
    }\
        QPushButton:checked {\
        background: rgb(105, 105, 105);\
    }\
    ");
    w.show();
    return a.exec();
}

注意,我为选中的按钮添加了一条额外的 CSS 规则,因此无论是否选中按钮,它都会可见。您确定您的按钮不起作用,或者您只是没有看到它们在起作用?!

EDIT2:如果它不适合您,您可以使用 setFlat(True),并使用其他 CSS 规则来修复颜色(如我的示例中所示)。

关于python - Qt:按钮上没有边框,使其不可点击?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3800757/

相关文章:

python - 使用 eventFilters 时,QTextEdit 光标出现问题

python - QTextBrowser 在 Mac 上显示 markdown,但在 Windows 上不显示

python - Subprocess.Popen Stdout 等待程序完成

python - 从具有可变长度的列表字典创建数据框

c++ - _BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 在 C++ 中崩溃

c++ - 体系结构 x86_64 jsonrpc 库的 undefined symbol

python - 在Python中使用QtCreator转换的文件

python - 序列化器中的权限检查,Django 休息框架,

javascript - PySide、QtWebKit 和 JavaScript 参数类型

c++ - 在 QLabel 中隐藏或裁剪重叠文本?