Q3GroupBox Class Reference

#include <q3groupbox.h>

Inheritance diagram for Q3GroupBox:

Inheritance graph
[legend]
Collaboration diagram for Q3GroupBox:

Collaboration graph
[legend]
List of all members.

Detailed Description

The Q3GroupBox widget provides a group box frame with a title.

A group box provides a frame, a title and a keyboard shortcut, and displays various other widgets inside itself. The title is on top, the keyboard shortcut moves keyboard focus to one of the group box's child widgets, and the child widgets are usually laid out horizontally (or vertically) inside the frame.

The simplest way to use it is to create a group box with the desired number of columns (or rows) and orientation, and then just create widgets with the group box as parent.

It is also possible to change the orientation() and number of columns() after construction, or to ignore all the automatic layout support and manage the layout yourself. You can add 'empty' spaces to the group box with addSpace().

Q3GroupBox also lets you set the title() (normally set in the constructor) and the title's alignment().

You can change the spacing used by the group box with setInsideMargin() and setInsideSpacing(). To minimize space consumption, you can remove the right, left and bottom edges of the frame with setFlat().

See also:
QButtonGroup

Definition at line 35 of file q3groupbox.h.

Public Types

enum  DummyFrame

Public Member Functions

 Q3GroupBox (QWidget *parent=0, const char *name=0)
 Q3GroupBox (const QString &title, QWidget *parent=0, const char *name=0)
 Q3GroupBox (int strips, Qt::Orientation o, QWidget *parent=0, const char *name=0)
 Q3GroupBox (int strips, Qt::Orientation o, const QString &title, QWidget *parent=0, const char *name=0)
 ~Q3GroupBox ()
virtual void setColumnLayout (int strips, Qt::Orientation o)
int columns () const
void setColumns (int)
Qt::Orientation orientation () const
void setOrientation (Qt::Orientation)
int insideMargin () const
int insideSpacing () const
void setInsideMargin (int m)
void setInsideSpacing (int s)
void addSpace (int)
void setFrameRect (QRect)
QRect frameRect () const
void setFrameShadow (DummyFrame)
DummyFrame frameShadow () const
void setFrameShape (DummyFrame)
DummyFrame frameShape () const
void setFrameStyle (int)
int frameStyle () const
int frameWidth () const
void setLineWidth (int)
int lineWidth () const
void setMargin (int margin)
int margin () const
void setMidLineWidth (int)
int midLineWidth () const

Protected Member Functions

void childEvent (QChildEvent *)
void resizeEvent (QResizeEvent *)
void changeEvent (QEvent *)

Private Member Functions

void skip ()
void init ()
void calculateFrame ()
void insertWid (QWidget *)

Private Attributes

Q3GroupBoxPrivated


Member Enumeration Documentation

enum Q3GroupBox::DummyFrame

Definition at line 67 of file q3groupbox.h.


Constructor & Destructor Documentation

Q3GroupBox::Q3GroupBox ( QWidget parent = 0,
const char *  name = 0 
) [explicit]

Constructs a group box widget with no title.

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

This constructor does not do automatic layout.

Definition at line 104 of file q3groupbox.cpp.

References init().

00105     : QGroupBox(parent, name)
00106 {
00107     init();
00108 }

Here is the call graph for this function:

Q3GroupBox::Q3GroupBox ( const QString title,
QWidget parent = 0,
const char *  name = 0 
) [explicit]

Constructs a group box with the title title.

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

This constructor does not do automatic layout.

Definition at line 119 of file q3groupbox.cpp.

References init(), QGroupBox::setTitle(), and QGroupBox::title().

00120     : QGroupBox(parent, name)
00121 {
00122     init();
00123     setTitle(title);
00124 }

Here is the call graph for this function:

Q3GroupBox::Q3GroupBox ( int  strips,
Qt::Orientation  orientation,
QWidget parent = 0,
const char *  name = 0 
)

Constructs a group box with no title. Child widgets will be arranged in strips rows or columns (depending on orientation).

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

Definition at line 135 of file q3groupbox.cpp.

References init(), and setColumnLayout().

00137     : QGroupBox(parent, name)
00138 {
00139     init();
00140     setColumnLayout(strips, orientation);
00141 }

Here is the call graph for this function:

Q3GroupBox::Q3GroupBox ( int  strips,
Qt::Orientation  orientation,
const QString title,
QWidget parent = 0,
const char *  name = 0 
)

Constructs a group box titled title. Child widgets will be arranged in strips rows or columns (depending on orientation).

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

Definition at line 152 of file q3groupbox.cpp.

References init(), setColumnLayout(), QGroupBox::setTitle(), and QGroupBox::title().

00155     : QGroupBox(parent, name)
00156 {
00157     init();
00158     setTitle(title);
00159     setColumnLayout(strips, orientation);
00160 }

Here is the call graph for this function:

Q3GroupBox::~Q3GroupBox (  ) 

Destroys the group box.

Definition at line 165 of file q3groupbox.cpp.

References d.

00166 {
00167     delete d;
00168 }


Member Function Documentation

void Q3GroupBox::setColumnLayout ( int  strips,
Qt::Orientation  direction 
) [virtual]

Changes the layout of the group box. This function is only useful in combination with the default constructor that does not take any layout information. This function will put all existing children in the new layout. It is not good Qt programming style to call this function after children have been inserted. Sets the number of columns or rows to be strips, depending on direction.

See also:
orientation columns

Definition at line 325 of file q3groupbox.cpp.

References QBoxLayout::addLayout(), Qt::AlignTop, QList< T >::at(), Q3GroupBoxPrivate::checkbox, QObject::children(), Q3GroupBoxPrivate::col, d, Q3GroupBoxPrivate::dir, Q3GroupBoxPrivate::grid, Qt::Horizontal, i, insertWid(), QList< T >::isEmpty(), QWidget::layout(), Q3GroupBoxPrivate::marg, Q3GroupBoxPrivate::nCols, Q3GroupBoxPrivate::nRows, o, Q3GroupBoxPrivate::row, QCoreApplication::sendPostedEvents(), QLayout::setAlignment(), QList< T >::size(), Q3GroupBoxPrivate::spac, and Q3GroupBoxPrivate::vbox.

Referenced by Q3GroupBox(), setColumns(), setInsideMargin(), setInsideSpacing(), and setOrientation().

00326 {
00327     if (layout())
00328         delete layout();
00329 
00330     d->vbox = 0;
00331     d->grid = 0;
00332 
00333     if (strips < 0) // if 0, we create the d->vbox but not the d->grid. See below.
00334         return;
00335 
00336     d->vbox = new QVBoxLayout(this, d->marg, 0);
00337 
00338     d->nCols = 0;
00339     d->nRows = 0;
00340     d->dir = direction;
00341 
00342     // Send all child events and ignore them. Otherwise we will end up
00343     // with doubled insertion. This won't do anything because d->nCols ==
00344     // d->nRows == 0.
00345     QApplication::sendPostedEvents(this, QEvent::ChildInserted);
00346 
00347     // if 0 or smaller , create a vbox-layout but no grid. This allows
00348     // the designer to handle its own grid layout in a group box.
00349     if (strips <= 0)
00350         return;
00351 
00352     d->dir = direction;
00353     if (d->dir == Qt::Horizontal) {
00354         d->nCols = strips;
00355         d->nRows = 1;
00356     } else {
00357         d->nCols = 1;
00358         d->nRows = strips;
00359     }
00360     d->grid = new QGridLayout(d->nRows, d->nCols, d->spac);
00361     d->row = d->col = 0;
00362     d->grid->setAlignment(Qt::AlignTop);
00363     d->vbox->addLayout(d->grid);
00364 
00365     // Add all children
00366     QObjectList childList = children();
00367     if (!childList.isEmpty()) {
00368         for (int i = 0; i < childList.size(); ++i) {
00369             QObject *o = childList.at(i);
00370             if (o->isWidgetType() && o != d->checkbox)
00371                 insertWid(static_cast<QWidget *>(o));
00372         }
00373     }
00374 }

Here is the call graph for this function:

int Q3GroupBox::columns (  )  const

Definition at line 226 of file q3groupbox.cpp.

References d, Q3GroupBoxPrivate::dir, Qt::Horizontal, Q3GroupBoxPrivate::nCols, and Q3GroupBoxPrivate::nRows.

Referenced by setInsideMargin(), setInsideSpacing(), and setOrientation().

00227 {
00228     if (d->dir == Qt::Horizontal)
00229         return d->nCols;
00230     return d->nRows;
00231 }

void Q3GroupBox::setColumns ( int   ) 

Definition at line 233 of file q3groupbox.cpp.

References d, Q3GroupBoxPrivate::dir, and setColumnLayout().

00234 {
00235     setColumnLayout(c, d->dir);
00236 }

Here is the call graph for this function:

Qt::Orientation Q3GroupBox::orientation (  )  const

Definition at line 310 of file q3groupbox.cpp.

References d, and Q3GroupBoxPrivate::dir.

00311 {
00312     return d->dir;
00313 }

void Q3GroupBox::setOrientation ( Qt::Orientation   ) 

Definition at line 304 of file q3groupbox.cpp.

References columns(), and setColumnLayout().

00305 {
00306     setColumnLayout(columns(), o);
00307 }

Here is the call graph for this function:

int Q3GroupBox::insideMargin (  )  const

Returns the width of the empty space between the items in the group and the frame of the group.

Only applies if the group box has a defined orientation.

The default is usually 11, by may vary depending on the platform and style.

See also:
setInsideMargin(), orientation

Definition at line 249 of file q3groupbox.cpp.

References d, and Q3GroupBoxPrivate::marg.

00250 {
00251     return d->marg;
00252 }

int Q3GroupBox::insideSpacing (  )  const

Returns the width of the empty space between each of the items in the group.

Only applies if the group box has a defined orientation.

The default is usually 5, by may vary depending on the platform and style.

See also:
setInsideSpacing(), orientation

Definition at line 265 of file q3groupbox.cpp.

References d, and Q3GroupBoxPrivate::spac.

00266 {
00267     return d->spac;
00268 }

void Q3GroupBox::setInsideMargin ( int  m  ) 

Sets the the width of the inside margin to m pixels.

See also:
insideMargin()

Definition at line 275 of file q3groupbox.cpp.

References columns(), d, Q3GroupBoxPrivate::dir, Q3GroupBoxPrivate::marg, and setColumnLayout().

00276 {
00277     d->marg = m;
00278     setColumnLayout(columns(), d->dir);
00279 }

Here is the call graph for this function:

void Q3GroupBox::setInsideSpacing ( int  s  ) 

Sets the width of the empty space between each of the items in the group to s pixels.

See also:
insideSpacing()

Definition at line 287 of file q3groupbox.cpp.

References columns(), d, Q3GroupBoxPrivate::dir, setColumnLayout(), and Q3GroupBoxPrivate::spac.

00288 {
00289     d->spac = s;
00290     setColumnLayout(columns(), d->dir);
00291 }

Here is the call graph for this function:

void Q3GroupBox::addSpace ( int  size  ) 

Adds an empty cell at the next free position. If size is greater than 0, the empty cell takes size to be its fixed width (if orientation() is Horizontal) or height (if orientation() is Vertical).

Use this method to separate the widgets in the group box or to skip the next free cell. For performance reasons, call this method after calling setColumnLayout() or by changing the Q3GroupBox::columns or Q3GroupBox::orientation properties. It is generally a good idea to call these methods first (if needed at all), and insert the widgets and spaces afterwards.

Definition at line 197 of file q3groupbox.cpp.

References QGridLayout::addItem(), Q3GroupBoxPrivate::col, d, Q3GroupBoxPrivate::dir, QSizePolicy::Fixed, Q3GroupBoxPrivate::grid, Qt::Horizontal, Q3GroupBoxPrivate::nCols, Q3GroupBoxPrivate::nRows, Q3GroupBoxPrivate::row, QCoreApplication::sendPostedEvents(), skip(), and Qt::Vertical.

00198 {
00199     QApplication::sendPostedEvents(this, QEvent::ChildInserted);
00200 
00201     if (d->nCols <= 0 || d->nRows <= 0)
00202         return;
00203 
00204     if (d->row >= d->nRows || d->col >= d->nCols)
00205         d->grid->expand(d->row+1, d->col+1);
00206 
00207     if (size > 0) {
00208         QSpacerItem *spacer
00209             = new QSpacerItem((d->dir == Qt::Horizontal) ? 0 : size,
00210                               (d->dir == Qt::Vertical) ? 0 : size,
00211                               QSizePolicy::Fixed, QSizePolicy::Fixed);
00212         d->grid->addItem(spacer, d->row, d->col);
00213     }
00214 
00215     skip();
00216 }

Here is the call graph for this function:

void Q3GroupBox::setFrameRect ( QRect   )  [inline]

Definition at line 65 of file q3groupbox.h.

00065 {}

QRect Q3GroupBox::frameRect (  )  const [inline]

Definition at line 66 of file q3groupbox.h.

00066 { return QRect(); }

void Q3GroupBox::setFrameShadow ( DummyFrame   )  [inline]

Definition at line 70 of file q3groupbox.h.

00070 {}

DummyFrame Q3GroupBox::frameShadow (  )  const [inline]

Definition at line 71 of file q3groupbox.h.

00071 { return Plain; }

void Q3GroupBox::setFrameShape ( DummyFrame   )  [inline]

Definition at line 72 of file q3groupbox.h.

00072 {}

DummyFrame Q3GroupBox::frameShape (  )  const [inline]

Definition at line 73 of file q3groupbox.h.

00073 { return NoFrame; }

void Q3GroupBox::setFrameStyle ( int   )  [inline]

Definition at line 74 of file q3groupbox.h.

00074 {}

int Q3GroupBox::frameStyle (  )  const [inline]

Definition at line 75 of file q3groupbox.h.

00075 { return 0; }

int Q3GroupBox::frameWidth (  )  const [inline]

Definition at line 76 of file q3groupbox.h.

00076 { return 0; }

void Q3GroupBox::setLineWidth ( int   )  [inline]

Definition at line 77 of file q3groupbox.h.

00077 {}

int Q3GroupBox::lineWidth (  )  const [inline]

Definition at line 78 of file q3groupbox.h.

00078 { return 0; }    

void Q3GroupBox::setMargin ( int  margin  )  [inline]

Since:
4.2
Sets the width of the margin around the contents of the widget to margin.

This function uses QWidget::setContentsMargins() to set the margin.

See also:
margin(), QWidget::setContentsMargins()

Definition at line 79 of file q3groupbox.h.

00079 { setContentsMargins(margin, margin, margin, margin); }

int Q3GroupBox::margin (  )  const [inline]

Since:
4.2
Returns the with of the the margin around the contents of the widget.

This function uses QWidget::getContentsMargins() to get the margin.

See also:
setMargin(), QWidget::getContentsMargins()

Definition at line 80 of file q3groupbox.h.

00081     { int margin; int dummy; getContentsMargins(&margin, &dummy, &dummy, &dummy);  return margin; }    

void Q3GroupBox::setMidLineWidth ( int   )  [inline]

Definition at line 82 of file q3groupbox.h.

00082 {}

int Q3GroupBox::midLineWidth (  )  const [inline]

Definition at line 83 of file q3groupbox.h.

00083 { return 0; }

void Q3GroupBox::childEvent ( QChildEvent c  )  [protected, virtual]

Reimplemented from QGroupBox.

Definition at line 377 of file q3groupbox.cpp.

References c, QGroupBox::childEvent(), d, Q3GroupBoxPrivate::grid, and insertWid().

00378 {
00379     QGroupBox::childEvent(c);
00380     if (!c->inserted() || !c->child()->isWidgetType())
00381         return;
00382     if (d->grid) {
00383         insertWid((QWidget*)c->child());
00384     }
00385 }

Here is the call graph for this function:

void Q3GroupBox::resizeEvent ( QResizeEvent e  )  [protected, virtual]

Reimplemented from QGroupBox.

Definition at line 178 of file q3groupbox.cpp.

References QGroupBox::resizeEvent().

00179 {
00180     QGroupBox::resizeEvent(e);
00181 }

Here is the call graph for this function:

void Q3GroupBox::changeEvent ( QEvent ev  )  [protected, virtual]

Reimplemented from QGroupBox.

Definition at line 418 of file q3groupbox.cpp.

References QGroupBox::changeEvent().

00419 {
00420     QGroupBox::changeEvent(ev);
00421 }

Here is the call graph for this function:

void Q3GroupBox::skip (  )  [private]

Definition at line 396 of file q3groupbox.cpp.

References Q3GroupBoxPrivate::col, d, Q3GroupBoxPrivate::dir, Qt::Horizontal, Q3GroupBoxPrivate::nCols, Q3GroupBoxPrivate::nRows, and Q3GroupBoxPrivate::row.

Referenced by addSpace(), and insertWid().

00397 {
00398     // Same as QGrid::skip()
00399     if (d->dir == Qt::Horizontal) {
00400         if (d->col+1 < d->nCols) {
00401             d->col++;
00402         } else {
00403             d->col = 0;
00404             d->row++;
00405         }
00406     } else { //Vertical
00407         if (d->row+1 < d->nRows) {
00408             d->row++;
00409         } else {
00410             d->row = 0;
00411             d->col++;
00412         }
00413     }
00414 }

void Q3GroupBox::init (  )  [private]

Definition at line 170 of file q3groupbox.cpp.

References d.

Referenced by Q3GroupBox().

00171 {
00172     d = new Q3GroupBoxPrivate();
00173 }

void Q3GroupBox::calculateFrame (  )  [private]

void Q3GroupBox::insertWid ( QWidget  )  [private]

Definition at line 387 of file q3groupbox.cpp.

References QGridLayout::addWidget(), Q3GroupBoxPrivate::col, d, Q3GroupBoxPrivate::grid, Q3GroupBoxPrivate::nCols, Q3GroupBoxPrivate::nRows, Q3GroupBoxPrivate::row, skip(), and w.

Referenced by childEvent(), and setColumnLayout().

00388 {
00389     if (d->row >= d->nRows || d->col >= d->nCols)
00390         d->grid->expand(d->row+1, d->col+1);
00391     d->grid->addWidget(w, d->row, d->col);
00392     skip();
00393 }

Here is the call graph for this function:


Member Data Documentation

Q3GroupBoxPrivate* Q3GroupBox::d [private]

Definition at line 95 of file q3groupbox.h.

Referenced by addSpace(), childEvent(), columns(), init(), insertWid(), insideMargin(), insideSpacing(), orientation(), setColumnLayout(), setColumns(), setInsideMargin(), setInsideSpacing(), skip(), and ~Q3GroupBox().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 15:59:40 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1