c++ - 隐藏 QPushButton 和 QLineEdit 边框

标签 c++ qt qstylesheet

我想隐藏那些边框

.

让它看起来像这样

我发现用 QT 创建一个漂亮的 GUI 非常困难,所以我想设计一个 PNG 背景并在其上放置一个透明对象,所以我的问题是如何隐藏 lineEdits 和QT中的按钮

最佳答案

一个可能的解决方案是通过属性使用 Qt Style Sheets

border-radius: some_value;

例子:

#include <QApplication>
#include <QLineEdit>
#include <QPushButton>
#include <QVBoxLayout>
#include <QWidget>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QString qss = "QWidget{"
                       "background-color: rgb(92, 53, 102);"
                       "}"
                       "QPushButton{"
                       "border-radius: 10px;"
                       "background-color: rgb(85, 87, 83);"
                       "}"
                       "QPushButton:pressed{"
                       " border-radius: 10px;"
                       "background-color: rgb(46, 52, 54);"
                       "}"
                       "QLineEdit {"
                       "border-radius: 10px;"
                       "background-color: rgb(173, 127, 168);"
                       "}";

    a.setStyleSheet(qss);
    QWidget widget;
    widget.setLayout(new QVBoxLayout);
    widget.layout()->addWidget(new QPushButton("button"));
    widget.layout()->addWidget(new QLineEdit);
    widget.show();
    return a.exec();
}

输出:

enter image description here

引用资料:

关于c++ - 隐藏 QPushButton 和 QLineEdit 边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48482500/

相关文章:

c++ - QPushButton 动态背景色

qt - 更改悬停并按下时的 QPushButton 图标

c++ - 如何使用线程将内容从一个文件复制到多个文件

c# - 如何在 C# 中编码 wstring *?

没有 super 用户访问权限的 C++ 类 ping 函数

c++ - 在 C++ 中如何创建一个可以将自身保存为变量的类?

python - QFile 无法打开包含 unicode 字符的文件名

c++ - 如何在 Qt 子类中处理信号?

c++ - 如果我有几个重叠的 QTimer 会发生什么

c++ - 光标仍然出现在 LineEdit 中,尽管它不再聚焦