Brandon Clark
Brandon Clark

Reputation: 796

QLineEdit rounded corners

Is there a way to round the corners of a QLineEdit widget? If not, is there a similar widget I could do this to?

Visual Meaning:

enter image description here

Upvotes: 9

Views: 8717

Answers (2)

SingerOfTheFall
SingerOfTheFall

Reputation: 29966

You can use StyleSheets to set styles of Qt components just like you would use them in making a website. You can set a stylesheet in two ways: in your application's code, or in QtDesiner.

To do it in QtDesiner (which is most convenient), right-click on the component which you have placed on the form, and press "Edit StyleSheet" (or maybe "Change Stylesheet", sorry, my Qt is not it English, so I'm not sure about the exact name of the option). A window will open that will let you edit the element's style sheet.

It is very convenient because it has some useful options like adding resources or colors or fonts right there, and you just need to press a couple of buttons to set the option you need through the GUI without the need to type or even to know CSS syntax.

From the code, you can do it like this (example):

SomeComponent->setStyleSheet("QLineEdit { border-radius: 5px; }");

Here is the documentation about the stylesheets.

Upvotes: 10

Rolle
Rolle

Reputation: 2980

Use stylesheets. From http://doc.qt.io/archives/qt-4.7/stylesheet-examples.html:

QLineEdit {
 border: 2px solid gray;
 border-radius: 10px;
}

Also, you can always override paintEvent if you want to get your hands dirty.

Upvotes: 5

Related Questions