6.0.0-rc4Source

QFrame Class

The QFrame class is the base class of widgets that can have a frame. More…

Header#include <QFrame>
CMaketarget_link_libraries(app PRIVATE Nt::Widgets)
ModuleNt Widgets C++ Classes
InheritsQWidget
Inherited byQAbstractScrollArea, QLCDNumber, QSplitter, QStackedWidget, QToolBox

List of all members, including inherited members

Public Types

enumShape
enumShadow

Public Functions

QFrame(QWidget *parent = nullptr)
~QFrame()
ShapeframeShape() const
voidsetFrameShape(Shape shape)
ShadowframeShadow() const
voidsetFrameShadow(Shadow shadow)
intframeStyle() const
voidsetFrameStyle(int style)
intlineWidth() const
voidsetLineWidth(int width)
intmidLineWidth() const
voidsetMidLineWidth(int width)
intframeWidth() const
QRectframeRect() const
QRectcontentsRect() const

Protected Functions

voiddrawFrame(QPainter *painter)

Reimplemented Protected Functions

voidpaintEvent(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.

QFrame in the light color scheme

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.

ConstantDescription
QFrame::PlainFlat, in the text color of the palette.
QFrame::RaisedRaised: light on the top and left, dark on the bottom and right.
QFrame::SunkenSunken: dark on the top and left, light on the bottom and right.

enum QFrame::Shape

This enum says what the frame draws.

ConstantDescription
QFrame::NoFrameNothing.
QFrame::BoxA rectangle around the contents.
QFrame::PanelA rectangle that looks raised or sunken.
QFrame::HLineA horizontal line, with nothing above or below it.
QFrame::VLineA vertical line, with nothing at its sides.
QFrame::StyledPanelA rectangle that the style draws, as it does the frame of other widgets.

Member Function Documentation

[explicit] QFrame::QFrame(QWidget *parent = nullptr)

Constructs a frame with no frame shape, and the given parent.

[override] QFrame::~QFrame()

Destroys the frame.

QRect QFrame::contentsRect() const

Returns the rectangle inside the frame.

See also frameWidth().

[protected] 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().

[override, protected] 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().