Qt logo

QFrame Class Reference


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

#include <qframe.h>

Inherits QWidget.

Inherited by QGrid, QGroupBox, QHBox, QLCDNumber, QLabel, QMenuBar, QPopupMenu, QProgressBar, QScrollView, QSpinBox, QSplitter, QTableView and QWidgetStack.

List of all member functions.

Public Members

Protected Members


Detailed Description

The QFrame class is the base class of widgets that (can) have a frame.

It draws a frame and calls a virtual function, drawContents(), to fill in the frame. This function is reimplemented by essentially all subclasses. There are also two other less useful functions, drawFrame() and frameChanged().

QMenuBar uses this to "raise" the menu bar above the surrounding screen:

    if ( style() == MotifStyle ) {
        setFrameStyle( QFrame::Panel | QFrame::Raised );
        setLineWidth( 2 );
    } else {
        setFrameStyle( QFrame::NoFrame );
    }

The QFrame class can also be used directly for creating simple frames without any contents, for example like this:

    QFrame *emptyFrame = new QFrame( parentWidget );
    emptyFrame->setFrameStyle( QFrame::Panel | QFrame::Sunken );
    emptyFrame->setLineWidth( 2 );

A frame widget has three attributes: frame style, a line width and a mid-line width.

The frame style is specified by a frame shape and a shadow style. The frame shapes are NoFrame, Box, Panel, StyledPanel WinPanel, HLine and VLine, and the shadow styles are Plain, Raised and Sunken.

The line width is the width of the frame border.

The mid-line width specifies the width of an extra line in the middle of the frame, that uses a third color to obtain a special 3D effect. Notice that a mid-line is only drawn for Box, HLine and VLine frames that are raised or sunken.

This table shows the most useful combinations of styles and widths (and some rather useless ones):

Table of frame styles

For obvious reasons, NoFrame isn't shown. The gray areas next to the VLine and HLine examples are there because the widgets in the illustration are taller/wider than the natural width of the lines. frameWidth() returns the natural width of the line.

The labels on the top and right are QLabel objects with frameStyle() Raised|Panel and lineWidth() 1.

Examples: xform/xform.cpp popup/popup.cpp scrollview/scrollview.cpp movies/main.cpp


Member Function Documentation

QFrame::QFrame(QWidget*parent=0, constchar*name=0, WFlagsf=0, bool=TRUE)

Constructs a frame widget with frame style NoFrame and a 1 pixel frame width.

The last argument exists for compatibility with Qt 1.x; it no longer has any meaning. (In Qt 2.x, QFrame always allows the HLine and VLine styles.)

The parent, name and f arguments are passed to the QWidget constructor.

QRectQFrame::contentsRect()const

Returns the rectangle inside the frame.

See also: frameRect() and drawContents().

voidQFrame::drawContents(QPainter*) [virtualprotected]

Virtual function that draws the contents of the frame.

The QPainter is already open when you get it, and you must leave it open. Painter transformations are switched off on entry. If you transform the painter, remember to take the frame into account and reset transformation before returning.

This function is reimplemented by subclasses that draw something inside the frame. It should draw only inside contentsRect(). The default function does nothing.

See also: contentsRect(), QPainter::setClipRect() and drawContentsMask().

Reimplemented in QMenuBar, QLabel, QProgressBar and QLCDNumber.

voidQFrame::drawContentsMask(QPainter*) [virtualprotected]

Virtual function that draws the mask of the frame's contents.

If you reimplemented drawContents(QPainter*) and your widget should support transparency you probably have to re-implement this function as well.

The default implementation is empty.

See also: drawContents(), updateMask(), QWidget::setAutoMask(), contentsRect() and QPainter::setClipRect().

Reimplemented in QLabel and QProgressBar.

voidQFrame::drawFrame(QPainter*p) [virtualprotected]

Draws the frame using the current frame attributes and color group. The rectangle inside the frame is not affected.

This function is virtual, but in general you do not need to reimplement it. If you do, note that the QPainter is already open and must remain open.

See also: frameRect(), contentsRect(), drawContents(), frameStyle(), setPalette() and drawFrameMask().

voidQFrame::drawFrameMask(QPainter*p) [virtualprotected]

Virtual function that draws the mask of the frame's frame.

If you reimplemented drawFrame(QPainter*) and your widget should support transparency you probably have to re-implement this function as well.

The default implementation is empty.

See also: drawFrame(), updateMask(), QWidget::setAutoMask() and QPainter::setClipRect().

voidQFrame::frameChanged() [virtualprotected]

Virtual function that is called when the frame style, line width or mid-line width changes.

This function can be reimplemented by subclasses that need to know when the frame attributes change.

The default implementation calls update().

Reimplemented in QHBox, QWidgetStack, QScrollView and QGrid.

QRectQFrame::frameRect()const

Returns the frame rectangle.

The default frame rectangle is equivalent to the widget rectangle.

See also: setFrameRect().

ShadowQFrame::frameShadow()const

Returns the frame shadow value from the frame style.

See also: setFrameShadow(), frameStyle() and frameShape().

ShapeQFrame::frameShape()const

Returns the frame shape value from the frame style.

See also: setFrameShape(), frameStyle() and frameShadow().

intQFrame::frameStyle()const

Returns the frame style.

The default value is QFrame::NoFrame.

See also: setFrameStyle(), frameShape() and frameShadow().

Examples: scrollview/scrollview.cpp

intQFrame::frameWidth()const

Returns the width of the frame that is drawn.

Note that the frame width depends on the frame style, not only the line width and the mid line width. For example, the style NoFrame always has a frame width 0, while the style Panel has a frame width equivalent to the line width. The frame width also includes the margin.

See also: lineWidth(), midLineWidth(), frameStyle() and margin().

intQFrame::lineWidth()const

Returns the line width. (Note that the total line width for HLine and VLine is given by frameWidth(), not lineWidth().)

The default value is 1.

See also: setLineWidth(), midLineWidth() and frameWidth().

Examples: scrollview/scrollview.cpp

intQFrame::margin()const

Returns the width of the margin. The margin is the distance between the innermost pixel of the frame and the outermost pixel of contentsRect(). It is included in frameWidth().

The margin is filled according to backgroundMode().

The default value is 0.

See also: setMargin(), lineWidth() and frameWidth().

Examples: scrollview/scrollview.cpp

intQFrame::midLineWidth()const

Returns the width of the mid-line.

The default value is 0.

See also: setMidLineWidth(), lineWidth() and frameWidth().

Examples: scrollview/scrollview.cpp

voidQFrame::paintEvent(QPaintEvent*event) [virtualprotected]

Handles paint events for the frame.

Paints the frame and the contents.

Opens the painter on the frame and calls first drawFrame(), then drawContents().

Reimplemented from QWidget.

voidQFrame::resizeEvent(QResizeEvent*e) [virtualprotected]

Handles resize events for the frame.

Adjusts the frame rectangle for the resized widget. The frame rectangle is elastic, the surrounding area is static.

The resulting frame rectangle may be null or invalid. You can use setMinimumSize() to avoid that possibility.

Nothing is done if the frame rectangle is a null rectangle already.

Reimplemented from QWidget.

voidQFrame::setFrameRect(constQRect&r) [virtual]

Sets the frame rectangle to r.

The frame rectangle is the rectangle the frame is drawn in. By default, this is the entire widget. Calling setFrameRect() does not cause a widget update.

If r is a null rectangle (for example QRect(0,0,0,0)), then the frame rectangle is equivalent to the widget rectangle.

See also: frameRect() and contentsRect().

Reimplemented in QWidgetStack.

voidQFrame::setFrameStyle(intstyle) [virtual]

Sets the frame style to style.

The style is the bitwise OR between a frame shape and a frame shadow style. See the illustration in the class documentation.

The frame shapes are:

The shadow styles are:

If a mid-line width greater than 0 is specified, an additional line is drawn for Raised or Sunken Box, HLine and VLine frames. The mid color of the current color group is used for drawing middle lines.

See also: Illustration, frameStyle(), colorGroup() and QColorGroup.

Examples: tabdialog/tabdialog.cpp xform/xform.cpp cursor/cursor.cpp layout/layout.cpp popup/popup.cpp scrollview/scrollview.cpp customlayout/main.cpp

voidQFrame::setLineWidth(intw) [virtual]

Sets the line width to w.

See also: frameWidth(), lineWidth() and setMidLineWidth().

Examples: xform/xform.cpp scrollview/scrollview.cpp

voidQFrame::setMargin(intw) [virtual]

Sets the width of the margin to w.

See also: margin() and setLineWidth().

Examples: tabdialog/tabdialog.cpp scrollview/scrollview.cpp

voidQFrame::setMidLineWidth(intw) [virtual]

Sets the width of the mid-line to w.

See also: midLineWidth() and setLineWidth().

Examples: scrollview/scrollview.cpp

QSizePolicyQFrame::sizePolicy()const [virtual]

If this is a line, it may stretch in the direction of the line, but it is fixed in the other direction. If this is a normal frame, use QWidget's default behavior.

Reimplemented from QWidget.

voidQFrame::updateMask() [virtualprotected]

Reimplementation of QWidget::updateMask(). Draws the mask of the frame when transparency is required.

This function calls the virtual functions drawFrameMask() and drawContentsMask(). These are the ones you may want to reimplement in subclasses.

See also: QWidget::setAutoMask(), drawFrameMask() and drawContentsMask().

Reimplemented from QWidget.


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright 1999 Troll TechTrademarks
Qt version 2.0.2