Skip to content

Commit 8cd52d0

Browse files
committed
new sexy lineedit widget with builtin clear button
1 parent 4215ea7 commit 8cd52d0

File tree

3 files changed

+68
-23
lines changed

3 files changed

+68
-23
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# -*- coding: utf-8 -*-
2+
3+
"""
4+
***************************************************************************
5+
FilterEdit.py
6+
---------------------
7+
Date : October 2012
8+
Copyright : (C) 2012 by Alexander Bruy
9+
Email : alexander dot bruy at gmail dot com
10+
***************************************************************************
11+
* *
12+
* This program is free software; you can redistribute it and/or modify *
13+
* it under the terms of the GNU General Public License as published by *
14+
* the Free Software Foundation; either version 2 of the License, or *
15+
* (at your option) any later version. *
16+
* *
17+
***************************************************************************
18+
"""
19+
20+
__author__ = 'Alexander Bruy'
21+
__date__ = 'October 2012'
22+
__copyright__ = '(C) 2012, Alexander Bruy'
23+
# This will get replaced with a git SHA1 when you do a git archive
24+
__revision__ = '$Format:%H$'
25+
26+
from PyQt4.QtCore import *
27+
from PyQt4.QtGui import *
28+
29+
import sextante.resources_rc
30+
31+
class FilterLineEdit(QLineEdit):
32+
def __init__(self, parent=None, placeholder="Filter"):
33+
QLineEdit.__init__(self, parent)
34+
35+
if hasattr(self, "setPlaceholderText"):
36+
self.setPlaceholderText(placeholder)
37+
38+
self.btnClear = QToolButton(self)
39+
self.btnClear.setIcon(QIcon(":/sextante/images/clear.png"))
40+
self.btnClear.setCursor(Qt.ArrowCursor)
41+
self.btnClear.setStyleSheet("QToolButton { border: none; padding: 0px; }")
42+
self.btnClear.hide()
43+
44+
self.btnClear.clicked.connect(self.clear)
45+
self.textChanged.connect(self.updateClearButton)
46+
47+
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
48+
self.setStyleSheet(QString("QLineEdit { padding-right: %1px; } ").arg(self.btnClear.sizeHint().width() + frameWidth + 1))
49+
msz = self.minimumSizeHint()
50+
self.setMinimumSize(max(msz.width(), self.btnClear.sizeHint().height() + frameWidth * 2 + 2),
51+
max(msz.height(), self.btnClear.sizeHint().height() + frameWidth * 2 + 2))
52+
53+
def resizeEvent(self, event):
54+
sz = self.btnClear.sizeHint()
55+
frameWidth = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
56+
self.btnClear.move(self.rect().right() - frameWidth - sz.width(),
57+
(self.rect().bottom() + 1 - sz.height())/2)
58+
59+
def updateClearButton(self, text):
60+
self.btnClear.setVisible(not text.isEmpty())

python/plugins/sextante/gui/SextanteToolbox.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242

4343
from sextante.ui.ui_SextanteToolbox import Ui_SextanteToolbox
4444

45-
import sextante.resources_rc
46-
4745
try:
4846
_fromUtf8 = QString.fromUtf8
4947
except AttributeError:
@@ -57,13 +55,10 @@ def __init__(self, iface):
5755

5856
self.iface=iface
5957

60-
self.btnClear.setIcon(QIcon(":/sextante/images/clear.png"))
61-
6258
self.externalAppsButton.clicked.connect(self.configureProviders)
6359
self.searchBox.textChanged.connect(self.fillTree)
6460
self.algorithmTree.customContextMenuRequested.connect(self.showPopupMenu)
6561
self.algorithmTree.doubleClicked.connect(self.executeAlgorithm)
66-
self.btnClear.clicked.connect(self.clearFilter)
6762

6863
self.fillTree()
6964

@@ -73,9 +68,6 @@ def algsListHasChanged(self):
7368
def updateTree(self):
7469
Sextante.updateAlgsList()
7570

76-
def clearFilter(self):
77-
self.searchBox.clear()
78-
7971
def configureProviders(self):
8072
webbrowser.open("http://docs.qgis.org/html/en/user_manual/sextante/3rdParty.html")
8173
#=======================================================================

python/plugins/sextante/ui/SextanteToolbox.ui

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,7 @@ additional algorithm providers</string>
3030
</widget>
3131
</item>
3232
<item>
33-
<layout class="QHBoxLayout" name="horizontalLayout">
34-
<property name="spacing">
35-
<number>2</number>
36-
</property>
37-
<item>
38-
<widget class="QLineEdit" name="searchBox"/>
39-
</item>
40-
<item>
41-
<widget class="QToolButton" name="btnClear">
42-
<property name="text">
43-
<string>...</string>
44-
</property>
45-
</widget>
46-
</item>
47-
</layout>
33+
<widget class="FilterLineEdit" name="searchBox"/>
4834
</item>
4935
<item>
5036
<widget class="QTreeWidget" name="algorithmTree">
@@ -64,6 +50,13 @@ additional algorithm providers</string>
6450
</layout>
6551
</widget>
6652
</widget>
53+
<customwidgets>
54+
<customwidget>
55+
<class>FilterLineEdit</class>
56+
<extends>QLineEdit</extends>
57+
<header>sextante.gui.FilterLineEdit</header>
58+
</customwidget>
59+
</customwidgets>
6760
<resources/>
6861
<connections/>
6962
</ui>

0 commit comments

Comments
 (0)