Skip to content

Commit

Permalink
fixing blinking introduced with the bold text
Browse files Browse the repository at this point in the history
  • Loading branch information
DoTheEvo committed Apr 6, 2015
1 parent 5610302 commit daa3c73
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions angrysearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self):
def initUI(self):
self.search_input = QLineEdit()
self.main_list = QListView()
self.main_list.setItemDelegate(HTMLDelegate())
self.upd_button = QPushButton('updatedb')

grid = QGridLayout()
Expand Down Expand Up @@ -240,7 +241,7 @@ def init_GUI(self):
def make_sys_tray(self):
if QSystemTrayIcon.isSystemTrayAvailable():
menu = QMenu()
menu.addAction('v0.9.0')
menu.addAction('v0.9.1')
menu.addSeparator()
exitAction = menu.addAction('Quit')
exitAction.triggered.connect(sys.exit)
Expand Down Expand Up @@ -304,7 +305,6 @@ def database_query_done(self, db_query_result):

def update_file_list_results(self, data):
model = QStringListModel(data)
self.center.main_list.setItemDelegate(HTMLDelegate())
self.center.main_list.setModel(model)
total = str(locale.format('%d', len(data), grouping=True))
self.status_bar.showMessage(total)
Expand Down Expand Up @@ -521,14 +521,18 @@ def sudo_dialog_receive_signal(self, message):

# CUSTOM DELEGATE TO GET HTML RICH TEXT IN LISTVIEW
class HTMLDelegate(QStyledItemDelegate):
def __init__(self, parent=None):
super(HTMLDelegate, self).__init__(parent)
self.doc = QTextDocument(self)
self.doc.setDocumentMargin(1)

def paint(self, painter, option, index):
options = QStyleOptionViewItem(option)
self.initStyleOption(options, index)
style = QApplication.style() if options.widget is None \
else options.widget.style()

doc = QTextDocument(self)
doc.setHtml(options.text)
self.doc.setHtml(options.text)

options.text = ""
style.drawControl(QStyle.CE_ItemViewItem, options, painter)
Expand All @@ -543,18 +547,17 @@ def paint(self, painter, option, index):
painter.save()
painter.translate(textRect.topLeft())
painter.setClipRect(textRect.translated(-textRect.topLeft()))
doc.documentLayout().draw(painter, ctx)
self.doc.documentLayout().draw(painter, ctx)

painter.restore()

def sizeHint(self, option, index):
options = QStyleOptionViewItem(option)
self.initStyleOption(options, index)
self.doc.setHtml(options.text)

doc = QTextDocument(self)
doc.setDocumentMargin(1)
doc.setHtml(options.text)
return QSize(doc.idealWidth(), 23)
return(QSize(self.doc.idealWidth(),
QStyledItemDelegate.sizeHint(self, option, index).height()))


def open_database():
Expand Down

0 comments on commit daa3c73

Please sign in to comment.