QWidget - set border from C++ code

Pyro2266 picture Pyro2266 · Mar 19, 2017 · Viewed 7.3k times · Source

I have QWidget instance (with other QWidgets inside) in Qt 5.8 and I want to set some border around it. Is there some way to do this from C++ without affecting any of it's children and their settings and positions?

I don't want to use stylesheets and it needs to work with any system style.

Answer

basslo picture basslo · Mar 19, 2017

you should use QFrame that inherits QWidget.

and set Frame::Shape in the method below to QFrame::Box. this will produce borders around your Frame.

QFrame::setFrameShape( QFrame::Shape); 

and use setLineWidth to set the lineWidth

QFrame::setLineWidth(int);