An expandable container with a QComboBox-style API. More...
#include <kexpandablegroupbox.h>


Classes | |
| class | Private |
Public Slots | |
| void | setExpanded (bool expanded) |
| void | setTitle (const QString &title) |
Public Member Functions | |
| KExpandableGroupBox (QWidget *parent=0) | |
| KExpandableGroupBox (const QString &title, QWidget *parent=0) | |
| ~KExpandableGroupBox () | |
| QString | title () const |
| bool | isExpanded () const |
| Qt::Alignment | alignment () const |
| QWidget * | widget () const |
| void | setWidget (QWidget *w) |
| void | setAlignment (Qt::Alignment a) |
| void | setAnimateExpansion (bool animate) |
| bool | animateExpansion () const |
| QSize | minimumSizeHint () const |
Protected Member Functions | |
| void | mouseReleaseEvent (QMouseEvent *ev) |
| void | paintEvent (QPaintEvent *) |
Properties | |
| bool | expanded |
| QString | title |
| Qt::Alignment | alignment |
| bool | animateExpansion |
An expandable container with a QComboBox-style API.
A KExpandableGroupBox provides a title label with space that you can store arbitrary widgets in, very much like a group box. However, unlike a group box, the contents is hidden by default and can be expanded by a click on the title or the folding indicator (+/-).
This class should be used within a QScrollArea, because the widget takes up more screen estate when unfolded and might otherwise enlarge your dialog beyond the physical screen size.
Example code:
QCheckBox *cb1 = new QCheckBox(tr("Option 1")); QCheckBox *cb2 = new QCheckBox(tr("Option 2")); QCheckBox *cb3 = new QCheckBox(tr("Option 3")); QWidget *widget = new QWidget; QVBoxLayout *vbox = new QVBoxLayout(widget); vbox->addWidget(cb1); vbox->addWidget(cb2); vbox->addWidget(cb3); KExpandableGroupBox *expWidget = new KExpandableGroupBox(); expWidget->setTitle(tr("Less Important Options")); expWidget->setWidget(widget); QScrollArea *area = new QScrollArea; area->setWindowTitle("Collapsible Widget Demo"); area->setWidgetResizable(true); QWidget *containerWidget = new QWidget QVBoxLayout *lay = new QVBoxLayout(containerWidget); lay->addWidget(collapsibleWidget);
| KExpandableGroupBox::KExpandableGroupBox | ( | QWidget * | parent = 0 |
) | [explicit] |
Default constructor.
| parent | is the parent widget |
Use setTitle() and setWidget() to set the respective properties.
: QWidget(parent), d(new KExpandableGroupBox::Private) { init(); }
Convinience constructor.
| title | is the title of the collaspsible widget | |
| parent | is the widget parent widget |
Use setWidget() to set the widgets contents.
: QWidget(parent), d(new KExpandableGroupBox::Private) { init(); setTitle(title); }
| KExpandableGroupBox::~KExpandableGroupBox | ( | ) |
{
delete d;
}
| Qt::Alignment KExpandableGroupBox::alignment | ( | ) | const |
| bool KExpandableGroupBox::animateExpansion | ( | ) | const |
| bool KExpandableGroupBox::isExpanded | ( | ) | const |
Referenced by mouseReleaseEvent(), and setWidget().
{
return d->colButton->isChecked();
}
| QSize KExpandableGroupBox::minimumSizeHint | ( | ) | const |
{
// return QSize(0,16);
return QWidget::minimumSizeHint();
}
| void KExpandableGroupBox::mouseReleaseEvent | ( | QMouseEvent * | ev | ) | [protected] |
Reimplemented from QWidget.
{
#if 0
if ( (ev->button() & Qt::LeftButton) && QRect(0, 0, width(), 16).contains(ev->pos())) {
setExpanded(!isExpanded());
}
#endif
QWidget::mouseReleaseEvent(ev);
}
| void KExpandableGroupBox::paintEvent | ( | QPaintEvent * | ev | ) | [protected] |
Reimplemented from QWidget.
{
#if 0
QPainter p(this);
QStyleOption opt;
int h = 16; //px
opt.rect = QRect(0, 0, h, h);
opt.palette = palette();
opt.state = QStyle::State_Children;
if (d->colButton->isChecked())
opt.state |= QStyle::State_Open;
style()->drawPrimitive(QStyle::PE_IndicatorBranch, &opt, &p);
p.drawText(h, 0, width(), height(), Qt::TextShowMnemonic, d->title);
p.end();
#endif
QWidget::paintEvent(ev);
}
| void KExpandableGroupBox::setAlignment | ( | Qt::Alignment | a | ) |
| void KExpandableGroupBox::setAnimateExpansion | ( | bool | animate | ) |
Sets wether or not the expansion of widget() should be animated.
{
d->animateExpansion = animate;
}
| void KExpandableGroupBox::setExpanded | ( | bool | expanded | ) | [slot] |
Sets wether the widgets contents is expanded or not
Referenced by mouseReleaseEvent(), and setWidget().
{
if ( !d->widget ) {
return;
}
if (!d->animateExpansion) {
if ( !expanded )
d->widget->setVisible( false );
} else {
if ( expanded )
d->expander->setVisible( true );
d->widget->setVisible( expanded );
}
d->colButton->setChecked( expanded );
d->timeline->setDirection( expanded ? QTimeLine::Forward
: QTimeLine::Backward );
d->timeline->start();
}
| void KExpandableGroupBox::setTitle | ( | const QString & | title | ) | [slot] |
| void KExpandableGroupBox::setWidget | ( | QWidget * | w | ) |
Sets the inner widgets.
Referenced by Seeker::Seeker().
{
if (!w) {
return;
}
d->widget = w;
d->label->setBuddy(d->widget);
if (!d->animateExpansion) {
if ( !isExpanded() ) {
d->widget->hide();
}
d->gridLayout->addWidget( d->widget, 2, 2 );
d->gridLayout->setRowStretch( 2, 1 );
} else {
if ( !d->expander ) {
d->expander = new QWidget( this );
d->gridLayout->addWidget( d->expander, 2, 2 );
d->gridLayout->setRowStretch( 2, 1 );
d->expanderLayout = new QVBoxLayout( d->expander );
d->expanderLayout->setMargin( 0 );
d->expanderLayout->setSpacing( 0 );
d->expander->setFixedHeight( 0 );
}
d->widget->setParent(d->expander);
d->widget->show();
d->expanderLayout->addWidget(d->widget);
}
setEnabled( true );
if ( isExpanded() ) {
setExpanded( true );
}
}
| QString KExpandableGroupBox::title | ( | ) | const |
| QWidget * KExpandableGroupBox::widget | ( | ) | const |
Qt::Alignment KExpandableGroupBox::alignment [read, write] |
bool KExpandableGroupBox::animateExpansion [read, write] |
bool KExpandableGroupBox::expanded [read, write] |
QString KExpandableGroupBox::title [read, write] |
1.7.1