Use action with icon instead of push button

Add action with an icon inside the line edit to clear the content of the line edit.
This commit is contained in:
Magne Sjaastad 2023-11-02 14:13:47 +01:00
parent 43c5705c8b
commit d8b842147b
4 changed files with 7 additions and 6 deletions

View File

@ -3,5 +3,6 @@
<file>Down16x16.png</file>
<file>Up16x16.png</file>
<file>duplicate.svg</file>
<file>clear.svg</file>
</qresource>
</RCC>

View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg fill="#000000" width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" d="M213.333333,3.55271368e-14 C269.912851,3.55271368e-14 324.175019,22.4761259 364.18278,62.4838867 C404.190541,102.491647 426.666667,156.753816 426.666667,213.333333 C426.666667,331.15408 331.15408,426.666667 213.333333,426.666667 C95.5125867,426.666667 3.55271368e-14,331.15408 3.55271368e-14,213.333333 C3.55271368e-14,95.5125867 95.5125867,3.55271368e-14 213.333333,3.55271368e-14 Z M213.333333,42.6666667 C119.076736,42.6666667 42.6666667,119.076736 42.6666667,213.333333 C42.6666667,307.589931 119.076736,384 213.333333,384 C307.589931,384 384,307.589931 384,213.333333 C384,119.076736 307.589931,42.6666667 213.333333,42.6666667 Z M288.758057,107.738721 L318.927946,137.90861 L243.502,213.333 L318.927946,288.758057 L288.758057,318.927946 L213.333,243.502 L137.90861,318.927946 L107.738721,288.758057 L183.163,213.333 L107.738721,137.90861 L137.90861,107.738721 L213.333,183.163 L288.758057,107.738721 Z" transform="translate(42.667 42.667)"/></svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -44,6 +44,7 @@
#include "cafQTreeViewStateSerializer.h"
#include "cafStyleSheetTools.h"
#include <QAction>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QPushButton>
@ -74,14 +75,13 @@ PdmUiTreeView::PdmUiTreeView( QWidget* parent, Qt::WindowFlags f )
m_searchBox = new QLineEdit( this );
m_searchBox->setPlaceholderText( "Type here to search in tree." );
searchLayout->addWidget( m_searchBox );
m_clearSearchButton = new QPushButton( "X" );
m_clearSearchButton->setMaximumSize( 30, 30 );
searchLayout->addWidget( m_clearSearchButton );
QAction* clearAction = m_searchBox->addAction( QIcon( ":/caf/clear.svg" ), QLineEdit::TrailingPosition );
connect( clearAction, &QAction::triggered, this, &PdmUiTreeView::slotOnClearSearchBox );
#if QT_VERSION >= QT_VERSION_CHECK( 5, 10, 0 )
m_layout->addLayout( searchLayout );
connect( m_searchBox, SIGNAL( textChanged( QString ) ), SLOT( slotOnSearchTextChanged() ) );
connect( m_clearSearchButton, SIGNAL( clicked() ), SLOT( slotOnClearSearchBox() ) );
#endif
m_treeViewEditor = new PdmUiTreeViewEditor();

View File

@ -46,7 +46,6 @@ class QItemSelection;
class QMenu;
class QModelIndex;
class QLineEdit;
class QPushButton;
class QSortFilterProxyModel;
namespace caf
@ -113,7 +112,6 @@ private:
QString m_uiConfigName;
QVBoxLayout* m_layout;
QLineEdit* m_searchBox;
QPushButton* m_clearSearchButton;
QString m_treeStateString;
};