Skip to content

Commit

Permalink
using horizontalAdvance instead of width when possible to avoid depre…
Browse files Browse the repository at this point in the history
…cation warnings (#715)
  • Loading branch information
aaronayres35 authored Oct 7, 2020
1 parent 61ac7e1 commit daa26ff
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
7 changes: 6 additions & 1 deletion pyface/ui/qt4/code_editor/code_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,12 @@ def sizeHint(self):
style = self.style()
opt = QtGui.QStyleOptionHeader()
font_metrics = QtGui.QFontMetrics(self.document().defaultFont())
width = font_metrics.width(" ") * 80
# QFontMetrics.width() is deprecated and Qt docs suggest using
# horizontalAdvance() instead, but is only available since Qt 5.11
if QtCore.__version_info__ >= (5, 11):
width = font_metrics.horizontalAdvance(" ") * 80
else:
width = font_metrics.width(" ") * 80
width += self.line_number_widget.sizeHint().width()
width += self.status_widget.sizeHint().width()
width += style.pixelMetric(QtGui.QStyle.PM_ScrollBarExtent, opt, self)
Expand Down
7 changes: 6 additions & 1 deletion pyface/ui/qt4/code_editor/find_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ def __init__(self, parent):
super(FindWidget, self).__init__(parent)
self.adv_code_widget = weakref.ref(parent)

self.button_size = self.fontMetrics().width("Replace All") + 20
# QFontMetrics.width() is deprecated and Qt docs suggest using
# horizontalAdvance() instead, but is only available since Qt 5.11
if QtCore.__version_info__ >= (5, 11):
self.button_size = self.fontMetrics().horizontalAdvance("Replace All") + 20
else:
self.button_size = self.fontMetrics().width("Replace All") + 20

form_layout = QtGui.QFormLayout()
form_layout.addRow("Fin&d", self._create_find_control())
Expand Down
14 changes: 11 additions & 3 deletions pyface/ui/qt4/code_editor/gutters.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,17 @@ def digits_width(self):
ndigits = max(
self.min_char_width, int(math.floor(math.log10(nlines) + 1))
)
width = max(
self.fontMetrics().width("0" * ndigits) + 3, self.min_width
)
# QFontMetrics.width() is deprecated and Qt docs suggest using
# horizontalAdvance() instead, but is only available since Qt 5.11
if QtCore.__version_info__ >= (5, 11):
width = max(
self.fontMetrics().horizontalAdvance("0" * ndigits) + 3,
self.min_width
)
else:
width = max(
self.fontMetrics().width("0" * ndigits) + 3, self.min_width
)
return width

def sizeHint(self):
Expand Down
7 changes: 6 additions & 1 deletion pyface/ui/qt4/code_editor/replace_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ def __init__(self, parent):
super(FindWidget, self).__init__(parent)
self.adv_code_widget = weakref.ref(parent)

self.button_size = self.fontMetrics().width("Replace All") + 20
# QFontMetrics.width() is deprecated and Qt docs suggest using
# horizontalAdvance() instead, but is only available since Qt 5.11
if QtCore.__version_info__ >= (5, 11):
self.button_size = self.fontMetrics().horizontalAdvance("Replace All") + 20
else:
self.button_size = self.fontMetrics().width("Replace All") + 20

form_layout = QtGui.QFormLayout()
form_layout.addRow("Fin&d", self._create_find_control())
Expand Down

0 comments on commit daa26ff

Please sign in to comment.