QLineEdit内容圆角样式表?

时间:2014-04-16 23:22:12

标签: qt qlineedit qtstylesheets

我正在使用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); } "
                   );

结果如下:

enter image description here

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

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

2 个答案:

答案 0 :(得分:2)

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

看起来像:

enter image description here

答案 1 :(得分:0)

要使border-radius值生效,请注意它取决于QLineEdit小部件的高度。例如,高度为20的QLineEdit小部件在停止绘制半径并恢复为方角之前,只能接受10px的border-radius值。如果你需要的话,尝试获得最大半径。