Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QWidget - set border from C++ code

Tags:

c++

qt

qwidget

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.

like image 445
Pyro2266 Avatar asked Mar 19 '17 18:03

Pyro2266


People also ask

What is QWidget in Qt?

The QWidget class provides the basic capability to render to the screen, and to handle user input events. All UI elements that Qt provides are either subclasses of QWidget, or are used in connection with a QWidget subclass.

What is a QFrame?

The QFrame class is the base class of widgets that can have a frame. QMenu uses this to "raise" the menu above the surrounding screen. QProgressBar has a "sunken" look. QLabel has a flat look. The frames of widgets like these can be changed.

What is stylesheet in Qt?

Qt Style Sheets are a powerful mechanism that allows you to customize the appearance of widgets, in addition to what is already possible by subclassing QStyle. The concepts, terminology, and syntax of Qt Style Sheets are heavily inspired by HTML Cascading Style Sheets (CSS) but adapted to the world of widgets.


1 Answers

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); 
like image 121
basslo Avatar answered Sep 20 '22 13:09

basslo