隐藏 QPushButton 和 QLineEdit 边框

Posted

技术标签:

【中文标题】隐藏 QPushButton 和 QLineEdit 边框【英文标题】:hide QPushButton and QLineEdit Borders 【发布时间】:2018-01-28 02:08:35 【问题描述】:

我想隐藏那些边框

.

让它看起来像这样

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

【问题讨论】:

你可以展示一张图片来说明你想要什么。 @eyllanesc 我已经编辑了我的帖子,您现在可以查看 你使用的是 QtWidgets 还是 QtQuick? @JonHarper QLineEdit 和 QPushButton 属于 QtWidgets 而不是 QtQuick 【参考方案1】:

一种可能的解决方案是通过属性使用 Qt 样式表

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();

输出:

参考资料:

http://doc.qt.io/qt-5/stylesheet-syntax.html http://doc.qt.io/qt-5/stylesheet-examples.html http://doc.qt.io/qt-5/stylesheet.html

【讨论】:

以上是关于隐藏 QPushButton 和 QLineEdit 边框的主要内容,如果未能解决你的问题,请参考以下文章