def helpEvent(self, event, view, option, index): if event is not None and view is not None and event.type() == QEvent.Type.ToolTip: try: db = index.model().db except AttributeError: return False try: book_id = db.id(index.row()) except (ValueError, IndexError, KeyError): return False db = db.new_api device_connected = self.parent().gui.device_connected on_device = device_connected is not None and db.field_for('ondevice', book_id) p = prepare_string_for_xml title = db.field_for('title', book_id) authors = db.field_for('authors', book_id) if title and authors: title = '<b>%s</b>' % ('<br>'.join(wrap(p(title), 120))) authors = '<br>'.join(wrap(p(' & '.join(authors)), 120)) tt = '%s<br><br>%s' % (title, authors) series = db.field_for('series', book_id) if series: use_roman_numbers=config['use_roman_numerals_for_series_number'] val = _('Book %(sidx)s of <span class="series_name">%(series)s</span>')%dict( sidx=fmt_sidx(db.field_for('series_index', book_id), use_roman=use_roman_numbers), series=p(series)) tt += '<br><br>' + val if on_device: val = _('This book is on the device in %s') % on_device tt += '<br><br>' + val QToolTip.showText(event.globalPos(), tt, view) return True return False
def helpEvent(self, ev, view, option, index): # Show a tooltip only if the item is truncated if not ev or not view: return False if ev.type() == QEvent.Type.ToolTip: rect = view.visualRect(index) size = self.sizeHint(option, index) if rect.width() < size.width(): tooltip = index.data(Qt.ItemDataRole.DisplayRole) QToolTip.showText(ev.globalPos(), tooltip, view) return True return QStyledItemDelegate.helpEvent(self, ev, view, option, index)
def show_tooltip(self, ev): c = self.cursorForPosition(ev.pos()) fmt_range = self.syntax_range_for_cursor(c) fmt = getattr(fmt_range, 'format', None) if fmt is not None: tt = unicode_type(fmt.toolTip()) if tt: QToolTip.setFont(self.tooltip_font) QToolTip.setPalette(self.tooltip_palette) QToolTip.showText(ev.globalPos(), textwrap.fill(tt)) return QToolTip.hideText() ev.ignore()
def show_tooltip(self, arg): widget, pos = arg QToolTip.showText(pos, self.get_tooltip())