Skip to content

Commit

Permalink
allow to expand/collapse when clicking on title
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky authored and dakcarto committed Sep 11, 2012
1 parent 3876b3e commit 0cc5923
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion src/gui/qgscollapsiblegroupbox.cpp
Expand Up @@ -21,7 +21,8 @@
#include "qgslogger.h"

#include <QToolButton>

#include <QMouseEvent>
#include <QStyleOptionGroupBox>

QIcon QgsCollapsibleGroupBox::mCollapseIcon;
QIcon QgsCollapsibleGroupBox::mExpandIcon;
Expand Down Expand Up @@ -55,6 +56,7 @@ void QgsCollapsibleGroupBox::init()
ss += " subcontrol-origin: margin;";
ss += " subcontrol-position: top left;";
ss += " margin-left: 20px;"; // offset for disclosure triangle
ss += " margin-right: 5px;"; // a little bit of space on the right, to match space on the left
ss += "}";
setStyleSheet( ss );

Expand Down Expand Up @@ -95,6 +97,25 @@ void QgsCollapsibleGroupBox::showEvent( QShowEvent * event )
}
}

void QgsCollapsibleGroupBox::mouseReleaseEvent( QMouseEvent *event )
{
// catch mouse release over title when non checkable, to collapse/expand
if ( !isCheckable() && event->button() == Qt::LeftButton )
{
QStyleOptionGroupBox box;
initStyleOption( &box );
QRect rect = style()->subControlRect( QStyle::CC_GroupBox, &box,
QStyle::SC_GroupBoxLabel, this );
if ( rect.contains( event->pos() ) )
{
toggleCollapsed();
return;
}
}
// default behaviour - pass to QGroupBox
QGroupBox::mouseReleaseEvent( event );
}

void QgsCollapsibleGroupBox::checkToggled( bool chkd )
{
mCollapseButton->setEnabled( true ); // always keep enabled
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgscollapsiblegroupbox.h
Expand Up @@ -49,7 +49,8 @@ class GUI_EXPORT QgsCollapsibleGroupBox : public QGroupBox

protected:
void init();
void showEvent( QShowEvent * event );
void showEvent( QShowEvent *event );
void mouseReleaseEvent( QMouseEvent *event );

private:
bool mCollapsed;
Expand Down

0 comments on commit 0cc5923

Please sign in to comment.