qt – QLineEdit内容上圆角的样式表?

我正在使用Qt样式表创建一个自定义QLineEdit,当它有焦点时,它周围有一个浅蓝色边框.这是样式表:

    this->setStyleSheet(" QLineEdit { "
                        " border-radius: 4px; "
                        " color:rgb(0, 0, 0); "
                        " background-color: rgb(255, 255, 255); } "

                        " QLineEdit:focus { "
                        " border-style:outset; "
                        " border-width:4px; "
                        " border-radius: 4px; "
                        " border-color: rgb(41, 237, 215); "
                        " color:rgb(0, 0, 0); "
                        " background-color: rgb(150, 150, 150); } "
                   );

这是结果:

这看起来很不错,但有没有办法绕过QLineEdit内容区域的角落?上图中的浅灰色区域?

更具体地说,Qt样式表可以降低吗?

最佳答案 border-radius应该大于border-width至少4-5 px.试试以下:

this->setStyleSheet(" QLineEdit { "
                        " border-radius: 8px; "
                        " color:rgb(0, 0, 0); "
                        " background-color: rgb(255, 255, 255); } "

                        " QLineEdit:focus { "
                        " border:4px outset; "
                        " border-radius: 8px; "
                        " border-color: rgb(41, 237, 215); "
                        " color:rgb(0, 0, 0); "
                        " background-color: rgb(150, 150, 150); } "
                   );

好像:

点赞