Add close button to SideBarWidget (#5133)
This commit is contained in:
committed by
Hyunjin Song
parent
57a486c75d
commit
867639929a
@@ -28,6 +28,7 @@
|
||||
#include <QPixmap>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
class SideBarWidget : public QWidget
|
||||
@@ -47,6 +48,8 @@ public:
|
||||
return m_title;
|
||||
}
|
||||
|
||||
signals:
|
||||
void closeButtonClicked();
|
||||
|
||||
protected:
|
||||
virtual void paintEvent( QPaintEvent * _pe );
|
||||
@@ -75,6 +78,8 @@ private:
|
||||
QVBoxLayout * m_layout;
|
||||
QString m_title;
|
||||
QPixmap m_icon;
|
||||
QPushButton * m_closeBtn;
|
||||
const QSize m_buttonSize;
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
@@ -121,6 +121,9 @@ void SideBar::appendTab( SideBarWidget *widget )
|
||||
widget->setMinimumWidth( 200 );
|
||||
|
||||
ToolTip::add( button, widget->title() );
|
||||
|
||||
connect(widget, &SideBarWidget::closeButtonClicked,
|
||||
[=]() { button->click(); });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -22,23 +22,31 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "SideBarWidget.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFontMetrics>
|
||||
#include <QPainter>
|
||||
|
||||
#include "SideBarWidget.h"
|
||||
#include "embed.h"
|
||||
|
||||
|
||||
SideBarWidget::SideBarWidget( const QString & _title, const QPixmap & _icon,
|
||||
QWidget * _parent ) :
|
||||
QWidget( _parent ),
|
||||
m_title( _title ),
|
||||
m_icon( _icon )
|
||||
m_icon(_icon),
|
||||
m_buttonSize(17, 17)
|
||||
{
|
||||
m_contents = new QWidget( this );
|
||||
m_layout = new QVBoxLayout( m_contents );
|
||||
m_layout->setSpacing( 5 );
|
||||
m_layout->setMargin( 0 );
|
||||
m_closeBtn = new QPushButton(embed::getIconPixmap("close"), QString(), this);
|
||||
m_closeBtn->resize(m_buttonSize);
|
||||
m_closeBtn->setToolTip(tr("Close"));
|
||||
connect(m_closeBtn, &QPushButton::clicked,
|
||||
[=]() { this->closeButtonClicked(); });
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +88,7 @@ void SideBarWidget::resizeEvent( QResizeEvent * )
|
||||
const int MARGIN = 6;
|
||||
m_contents->setGeometry( MARGIN, 40 + MARGIN, width() - MARGIN * 2,
|
||||
height() - MARGIN * 2 - 40 );
|
||||
m_closeBtn->move(m_contents->geometry().width() - MARGIN - 5, 5);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user