Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing border of QLineEdit

Tags:

qt

qlineedit

I have a bunch of QLineEdit boxes that I want to remove the borders from. Ideally I want to just do this with one line of code, rather than having to set no border for each QLineEdit box. I am trying to use QLineEdit::setFrame(false); but this returns illegal call of non-static member function. Suggestions?

like image 442
user2494298 Avatar asked Feb 10 '14 18:02

user2494298


1 Answers

You can set the style sheet for the application, or for the parent of those line edits:

window()->setStyleSheet("QLineEdit { border: none }");

or

window()->setStyleSheet("QLineEdit { qproperty-frame: false }");

The latter is equivalent to executing the following code:

for(auto ed : window()->findChildren<QLineEdit*>())
  ed->setFrame(false);

The window() refers to QWidget * QWidget::window() const.

Since you want to do it application-wide, you can simply set the style sheet on the application:

qApp->setStyleSheet("QLineEdit { qproperty-frame: false }");

You can further use CSS selectors to override the frame on certain objects. You've got the power of CSS at your disposal.

like image 92
Kuba hasn't forgotten Monica Avatar answered Sep 21 '22 18:09

Kuba hasn't forgotten Monica