Skip to content
Permalink
Browse files

allow to expand/collapse when clicking on title

  • Loading branch information
etiennesky authored and dakcarto committed Sep 11, 2012
1 parent 3876b3e commit 0cc5923a7516e6476af7b7f3126930dbc2599c53
Showing with 24 additions and 2 deletions.
  1. +22 −1 src/gui/qgscollapsiblegroupbox.cpp
  2. +2 −1 src/gui/qgscollapsiblegroupbox.h
@@ -21,7 +21,8 @@
#include "qgslogger.h"

#include <QToolButton>

#include <QMouseEvent>
#include <QStyleOptionGroupBox>

QIcon QgsCollapsibleGroupBox::mCollapseIcon;
QIcon QgsCollapsibleGroupBox::mExpandIcon;
@@ -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 );

@@ -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
@@ -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;

0 comments on commit 0cc5923

Please sign in to comment.
You can’t perform that action at this time.