[PATCH] commit: fix wrong size of commit button on Qt6

6 views
Skip to first unread message

Antonio Muci

unread,
Jun 22, 2026, 4:42:01 PM (2 days ago) Jun 22
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1781552080 -7200
# Mon Jun 15 21:34:40 2026 +0200
# Node ID 38d32d6d81f7f9886c12d0b6db0af287001f788a
# Parent 9806d49225a505445a9b2bbde5037e3ffa6f1006
commit: fix wrong size of commit button on Qt6

This commit redoes verbatim what was proposed in 2024 in
https://groups.google.com/g/thg-dev/c/o0AgzdVKazo/m/4soNAHtFBgAJ by Matt
Harbison.

At the time, it was rejected because ".width() at this point wouldn't return
reasonable value because the widget isn't laid out yet".

On my system (Fedora 44, PyQt6), print(committb.width()) prints 100 and fixes
the visual issue, without breaking when run under PyQt5. However, I only tested
on my system with PyQt5 and PyQt6. For example, I did not do any Windows
testing.

The patch also removes the function menuButtonWidth(), which has no callers
left. The introduction of menuButtonWidth() can be tracked back to afe08b4e6fd6
from 2011.

Fixes #5968 (that also contains screenshots before and after the change).

diff --git a/tortoisehg/hgqt/commit.py b/tortoisehg/hgqt/commit.py
--- a/tortoisehg/hgqt/commit.py
+++ b/tortoisehg/hgqt/commit.py
@@ -484,13 +484,6 @@ class CommitWidget(QWidget, qtlib.TaskWi
opt = QStyleOptionToolButton()
opt.initFrom(self)
return opt
- def menuButtonWidth(self):
- style = self.style()
- opt = self.styleOption()
- opt.features = QStyleOptionToolButton.ToolButtonFeature.MenuButtonPopup
- rect = style.subControlRect(QStyle.ComplexControl.CC_ToolButton, opt,
- QStyle.SubControl.SC_ToolButtonMenu, self)
- return rect.width()
def setBold(self):
f = self.font()
f.setWeight(QFont.Weight.Bold)
@@ -504,7 +497,7 @@ class CommitWidget(QWidget, qtlib.TaskWi
committb.setPopupMode(QToolButton.ToolButtonPopupMode.MenuButtonPopup)
fmk = lambda s: committb.fontMetrics().horizontalAdvance(hglib.tounicode(s[2]))
committb._width = (max(pycompat.maplist(fmk, acts))
- + 4*committb.menuButtonWidth())
+ + committb.width())

class CommitButtonMenu(QMenu):
def __init__(self, parent, repo):

Antonio Muci

unread,
Jun 22, 2026, 4:46:19 PM (2 days ago) Jun 22
to thg...@googlegroups.com
I have sent this patch for the "default" branch, since I think it would
be better to give it more testing time.

The patch also applies cleanly to "stable", where I actually tested it.
Feel free to queue it there, if wanted. If "default" has to be brought
back from the dead, it should obviously be synced with the current stable.

Yuya Nishihara

unread,
Jun 23, 2026, 9:36:25 AM (yesterday) Jun 23
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
On Mon, 22 Jun 2026 22:41:58 +0200, 'Antonio Muci' via TortoiseHg Developers wrote:
> # HG changeset patch
> # User Antonio Muci <a....@inwind.it>
> # Date 1781552080 -7200
> # Mon Jun 15 21:34:40 2026 +0200
> # Node ID 38d32d6d81f7f9886c12d0b6db0af287001f788a
> # Parent 9806d49225a505445a9b2bbde5037e3ffa6f1006
> commit: fix wrong size of commit button on Qt6
>
> This commit redoes verbatim what was proposed in 2024 in
> https://groups.google.com/g/thg-dev/c/o0AgzdVKazo/m/4soNAHtFBgAJ by Matt
> Harbison.
>
> At the time, it was rejected because ".width() at this point wouldn't return
> reasonable value because the widget isn't laid out yet".
>
> On my system (Fedora 44, PyQt6), print(committb.width()) prints 100 and fixes

It means the width isn't known yet. 100px is probably the default initial value.
Can't we instead add some fixed upper bound to keep the button small?

Antonio Muci

unread,
9:13 AM (6 hours ago) 9:13 AM
to thg...@googlegroups.com, a....@inwind.it
# HG changeset patch
# User Antonio Muci <a....@inwind.it>
# Date 1782306386 -7200
# Wed Jun 24 15:06:26 2026 +0200
# Branch stable
# Node ID a49ba77124c6b82f849142b18d7121b4b49d0912
# Parent 15d028aec364def81d4b2fb952db5dbeec5bf128
commit: fix wrong size of commit button on Qt6

On my system (Fedora 44, PyQt6) this change fixes the visual issue, without
breaking when run under PyQt5. However, I only tested on my system (linux,
Fedora 44). For example, I did not do any Windows testing.

The patch also removes the function menuButtonWidth(), which has no callers
left. The introduction of menuButtonWidth() can be tracked back to afe08b4e6fd6
from 2011.

Discussions at:
https://groups.google.com/g/thg-dev/c/rdFlpNnMVto (2026)
https://groups.google.com/g/thg-dev/c/o0AgzdVKazo/m/4soNAHtFBgAJ (2024)

Fixes #5968 (that also contains screenshots before and after the change).

diff --git a/tortoisehg/hgqt/commit.py b/tortoisehg/hgqt/commit.py
--- a/tortoisehg/hgqt/commit.py
+++ b/tortoisehg/hgqt/commit.py
@@ -486,13 +486,6 @@ class CommitWidget(QWidget, qtlib.TaskWi
opt = QStyleOptionToolButton()
opt.initFrom(self)
return opt
- def menuButtonWidth(self):
- style = self.style()
- opt = self.styleOption()
- opt.features = QStyleOptionToolButton.ToolButtonFeature.MenuButtonPopup
- rect = style.subControlRect(QStyle.ComplexControl.CC_ToolButton, opt,
- QStyle.SubControl.SC_ToolButtonMenu, self)
- return rect.width()
def setBold(self):
f = self.font()
f.setWeight(QFont.Weight.Bold)
@@ -505,8 +498,7 @@ class CommitWidget(QWidget, qtlib.TaskWi
committb.setBold()
committb.setPopupMode(QToolButton.ToolButtonPopupMode.MenuButtonPopup)
fmk = lambda s: committb.fontMetrics().horizontalAdvance(hglib.tounicode(s[2]))
- committb._width = (max(pycompat.maplist(fmk, acts))
- + 4*committb.menuButtonWidth())
+ committb._width = (max(pycompat.maplist(fmk, acts)) + 50)

Yuya Nishihara

unread,
9:58 AM (6 hours ago) 9:58 AM
to 'Antonio Muci' via TortoiseHg Developers, a....@inwind.it
Can you also remove styleOption() and QStyleOptionToolButton?
Reply all
Reply to author
Forward
0 new messages