Qt:按钮上没有边框使它们不可点击? [英] Qt: No border on buttons making them non-clickable?

查看:132
本文介绍了Qt:按钮上没有边框使它们不可点击?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to set a style to a button so that it has no border, but it seems the lack of border then makes the button non-clickable. Is there a better way of getting no border?

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;}")

推荐答案

WHOOPS,刚刚注意到这是一个关于 Qt/Python(而不是 Qt/C++)的问题,好吧,也许我的回答无论如何都会有所帮助..

WHOOPS, just noticed this is a Question regarding Qt/Python (and not Qt/C++), well maybe my answer helps anyways..

刚试过,对我有用...这是我使用的代码:

Just tried it, and it works for me... Here is the code i used:

#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 规则,因此无论是否选中按钮,它都是可见的.您确定您的按钮不起作用,还是可能只是您没有看到它们在起作用?!

notice i added a additional CSS rule for checked buttons, so it gets visible if a Button is checked or not. Are you sure your buttons dont work, or could it be, that you just dont see that they are working ?!

如果它不适合你,你可以使用 setFlat(True),并使用额外的 CSS 规则来修复颜色(就像我的例子一样).

If it doesnt work for you, you could just use setFlat(True), and use additional CSS rules to fix the colors (like in my example).

这篇关于Qt:按钮上没有边框使它们不可点击?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆