QFrame Class
The QFrame class is the base class of widgets that can have a frame. More…
| Header | #include <QFrame> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Widgets) |
| Module | Nt Widgets C++ Classes |
| Inherits | QWidget |
| Inherited by | QAbstractScrollArea, QLCDNumber, QSplitter, QStackedWidget, QToolBox |
List of all members, including inherited members
Public Types
Public Functions
| QFrame(QWidget *parent = nullptr) | |
| ~QFrame() | |
| Shape | frameShape() const |
| void | setFrameShape(Shape shape) |
| Shadow | frameShadow() const |
| void | setFrameShadow(Shadow shadow) |
| int | frameStyle() const |
| void | setFrameStyle(int style) |
| int | lineWidth() const |
| void | setLineWidth(int width) |
| int | midLineWidth() const |
| void | setMidLineWidth(int width) |
| int | frameWidth() const |
| QRect | frameRect() const |
| QRect | contentsRect() const |
Protected Functions
Reimplemented Protected Functions
| void | paintEvent(QPaintEvent *event) |
Detailed Description
A frame has a shape, which says what is drawn, and a shadow, which says how it looks: flat, raised or sunken. Set both at once with setFrameStyle():
QFrame *line = new QFrame(window);
line->setFrameStyle(QFrame::HLine | QFrame::Sunken);
A frame draws its shape in lineWidth() pixels, and, for a raised or sunken box, midLineWidth() pixels of the window color between the two shaded lines. A StyledPanel is drawn by the style, so it looks like the frames of the other widgets; its width comes from the style.
A QFrame draws nothing but its frame. A widget that is a QFrame keeps its own contents inside contentsRect().
Frame shapes in the light color scheme: a box, a panel, a sunken and a raised line, and a styled panel.

See also QLabel and QGroupBox.
Differences from Qt
There is no WinPanel shape, no setFrameRect(), and no QFrame::StyleMask or QFrame::Shadow_Mask. The frame is always the whole widget. contentsRect() is a member of QFrame, not of QWidget, and is the rectangle inside the frame; there are no contents margins.
Member Type Documentation
enum QFrame::Shadow
This enum says how the lines of the frame look.
| Constant | Description |
|---|---|
QFrame::Plain | Flat, in the text color of the palette. |
QFrame::Raised | Raised: light on the top and left, dark on the bottom and right. |
QFrame::Sunken | Sunken: dark on the top and left, light on the bottom and right. |
enum QFrame::Shape
This enum says what the frame draws.
| Constant | Description |
|---|---|
QFrame::NoFrame | Nothing. |
QFrame::Box | A rectangle around the contents. |
QFrame::Panel | A rectangle that looks raised or sunken. |
QFrame::HLine | A horizontal line, with nothing above or below it. |
QFrame::VLine | A vertical line, with nothing at its sides. |
QFrame::StyledPanel | A rectangle that the style draws, as it does the frame of other widgets. |
Member Function Documentation
QFrame::QFrame(QWidget *parent = nullptr)
Constructs a frame with no frame shape, and the given parent.
QFrame::~QFrame()
Destroys the frame.
QRect QFrame::contentsRect() const
Returns the rectangle inside the frame.
See also frameWidth().
void QFrame::drawFrame(QPainter *painter)
Draws the frame with painter, in the rectangle of the widget. paintEvent() does it; a subclass that draws something else in its own paintEvent() calls it to have the frame.
QRect QFrame::frameRect() const
Returns the rectangle of the frame, which is the whole widget.
Shadow QFrame::frameShadow() const
Returns how the lines of the frame look.
See also setFrameShadow() and frameShape().
Shape QFrame::frameShape() const
Returns the shape of the frame.
See also setFrameShape() and frameShadow().
int QFrame::frameStyle() const
Returns the shape and the shadow of the frame, as in QFrame::Box | QFrame::Raised.
See also setFrameStyle().
int QFrame::frameWidth() const
Returns the width of the frame: how far its contents are from the edge of the widget. It is 0 without a frame, the width from the style for a styled panel, and otherwise from lineWidth() and midLineWidth().
See also contentsRect().
int QFrame::lineWidth() const
Returns the width of the lines of the frame, 1 by default.
See also setLineWidth() and midLineWidth().
int QFrame::midLineWidth() const
Returns the width of the line between the two shaded lines of a raised or sunken box, 0 by default.
See also setMidLineWidth() and lineWidth().
void QFrame::paintEvent(QPaintEvent *event)
Reimplements QWidget::paintEvent().
void QFrame::setFrameShadow(Shadow shadow)
Sets the shadow of the frame to shadow.
See also frameShadow().
void QFrame::setFrameShape(Shape shape)
Sets the shape of the frame to shape.
See also frameShape().
void QFrame::setFrameStyle(int style)
Sets the shape and the shadow of the frame to style, a shape and a shadow combined with |. A shadow of 0 is the same as Plain.
See also frameStyle(), setFrameShape() and setFrameShadow().
void QFrame::setLineWidth(int width)
Sets the width of the lines of the frame to width pixels.
See also lineWidth().
void QFrame::setMidLineWidth(int width)
Sets the width of the middle line of the frame to width pixels.
See also midLineWidth().