문제

I'm using Qt style sheets to create a custom QLineEdit that has a light blue border around it when it has focus. Here is the style sheet :

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

And here is the result:

enter image description here

This looks pretty good, but is there any way to round the corners of the QLineEdit content area? The light gray region in the above image?

More specifically, can this be down with Qt style sheets?

도움이 되었습니까?

해결책

border-radius should be bigger then border-width at least 4-5 px. Try following:

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

Looks like:

enter image description here

다른 팁

For the border-radius value to have an effect, note that it is dependent upon the height of the QLineEdit widget. For example, a QLineEdit widget with a height of 20 can only accept a border-radius value of 10px before it stops drawing a radius and reverts to square corners. Experiment to get the maximum radius if that's what you need.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top