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?

AAEM
  • 1,837
  • 2
  • 18
  • 26
user2494298
  • 299
  • 3
  • 7
  • 23

2 Answers2

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.

Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
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 );

Dimitry Ernot
  • 6,256
  • 2
  • 25
  • 37
  • 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? – user2494298 Feb 10 '14 at 19:11