Removing border of QLineEdit
Asked Answered
E

2

9

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?

Ebneter answered 10/2, 2014 at 18:59 Comment(0)
G
21

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.

Gauvin answered 10/2, 2014 at 19:12 Comment(0)
D
4

Use QLineEdit::setFrame() for that. But yes, it isn't a static method. So, you have to call it on an object : myLineEdit->setFrame( false );

Dante answered 10/2, 2014 at 19:3 Comment(1)
I know but I have about 200 QLineEdits, which means I would have to go threw and do this for every one. There isn't a way to just globally do it?Ebneter

© 2022 - 2024 — McMap. All rights reserved.