[PATCH 0 of 1 qt] RFC: selection rendering for delegated cells

32 views
Skip to first unread message

George Marrows

unread,
Jun 21, 2010, 1:24:16 PM6/21/10
to thg...@googlegroups.com
I'm trying to tidy up rendering of selected Log cells in the repo viewer.

On Windows the following attempt gets close: it's all working (ie focussed
and unfocussed and font style) except for selected text not being drawn
in white.

However, it's a backward step for grep results:
- no monospace font for results (though I actually prefer the standard font)
- selected text not drawn in white.

Btw on Vista, the grep results don't render correctly with or without this
patch: selections there are done using a transparent overlay which I can't
yet persuade Qt to render for us. Diff between grep results and repo viewer
seems to be because former uses QTreeView and latter QTableView.

-- George

George Marrows

unread,
Jun 21, 2010, 1:24:17 PM6/21/10
to thg...@googlegroups.com
# HG changeset patch
# User George Marrows
# Date 1277139499 -3600
# Node ID 7fd925d6075d831aea153ce95d0f9d4d04db9d65
# Parent 6037714804fbe6f22ab93a26882dcdb5a158a353
htmllistview: draw selection using drawControl()

diff --git a/tortoisehg/hgqt/htmllistview.py b/tortoisehg/hgqt/htmllistview.py
--- a/tortoisehg/hgqt/htmllistview.py
+++ b/tortoisehg/hgqt/htmllistview.py
@@ -94,18 +94,15 @@
if self.cols and index.column() not in self.cols:
return QStyledItemDelegate.paint(self, painter, option, index)
text = index.model().data(index, Qt.DisplayRole).toString()
- palette = QApplication.palette()
+
+ # draw selection
+ option = QStyleOptionViewItemV4(option)
+ self.parent().style().drawControl(QStyle.CE_ItemViewItem, option, painter)
+
+ # draw text
doc = QTextDocument()
- doc.setDefaultFont(option.font)
- doc.setDefaultStyleSheet(qtlib.thgstylesheet)
painter.save()
- if option.state & QStyle.State_Selected:
- doc.setHtml('<font color=%s>%s</font>' % (
- palette.highlightedText().color().name(), text))
- bgcolor = palette.highlight().color()
- painter.fillRect(option.rect, bgcolor)
- else:
- doc.setHtml(text)
+ doc.setHtml(text)
painter.translate(option.rect.topLeft());
painter.setClipRect(option.rect.translated(-option.rect.topLeft()))
doc.drawContents(painter)

George Marrows

unread,
Jun 21, 2010, 1:33:36 PM6/21/10
to thg...@googlegroups.com
Here's the before and after screenshots on Vista. Note that the
correct selection highlight style is the transparent bar visible on
the left (file / line columns).

If anyone was willing to provide similar screenshots for other
platforms, that'd be much appreciated.

-- George

before.png
after.png

Steve Borho

unread,
Jun 21, 2010, 2:17:57 PM6/21/10
to thg...@googlegroups.com

Looks much better on Linux as well, pushed.

The only side-effect that remains, near as I can tell, is that the
text is slightly lower than the other columns.

--
Steve Borho

Johan Samyn

unread,
Jun 21, 2010, 2:58:58 PM6/21/10
to thg...@googlegroups.com
2010/6/21 Steve Borho <st...@borho.org>
Looks much better on Win7 too. Text is not clipped anymore (even with my display settings at 125%).
Same remark as Steve : text looks vertically aligned at the bottom instead of centered in the box.
Font is also smaller than the other columns, but I guess that's part of the todo ?
I added a screenshot, as you requested earlier.
--
Johan

TortoiseHg_Workbench.png

André Sintzoff

unread,
Jun 21, 2010, 3:17:13 PM6/21/10
to thg...@googlegroups.com
2010/6/21 Johan Samyn <johan...@gmail.com>:

On Mac OS X, same remark for the text alignement.
For the font size, it is good.

Screenshot attached

André

thg-workbench-mac.png

George Marrows

unread,
Jun 21, 2010, 3:54:03 PM6/21/10
to thg...@googlegroups.com
Thanks for the screenshots guys. I'll keeping thinking/researching on
and off about the alignment and font size and grep problems, but I'm
not going to focus on it right now as it's just too depressing wading
through the Qt docs and code ;-) I hope that's ok.

> even with my display settings at 125%

Johan - are you using the Win7 equivalent of Vista's DPI Scaling?
http://www.lawfirmsoftware.com/learning_center/howto/change_dpi_settings_vista.htm

More screenshots always welcome. Steve - could you do a Linux one perhaps?

-- George

Steve Borho

unread,
Jun 21, 2010, 3:56:44 PM6/21/10
to thg...@googlegroups.com

Enjoy

--
Steve Borho

Screenshot.png

Johan Samyn

unread,
Jun 21, 2010, 4:06:52 PM6/21/10
to thg...@googlegroups.com


2010/6/21 George Marrows <george....@googlemail.com>

Thanks for the screenshots guys. I'll keeping thinking/researching on
and off about the alignment and font size and grep problems, but I'm
not going to focus on it right now as it's just too depressing wading
through the Qt docs and code ;-)  I hope that's ok.

> even with my display settings at 125%
Johan - are you using the Win7 equivalent of Vista's DPI Scaling?
http://www.lawfirmsoftware.com/learning_center/howto/change_dpi_settings_vista.htm
Yeah, pretty much looks like that.

Adrian Buehlmann

unread,
Jun 21, 2010, 6:28:15 PM6/21/10
to thg...@googlegroups.com, George Marrows

Attaching Windows 7 Ultimate x64 screenshot.

Done with pushed revision 7dd3ffb36a69.


Capture.PNG

Johan Samyn

unread,
Jun 22, 2010, 2:45:17 AM6/22/10
to thg...@googlegroups.com
2010/6/22 Adrian Buehlmann <adr...@cadifra.com>
I can't tell for sure from your screenshot, Adrian, but does your screenshot show a smaller font for the Log column too, just like mine (Win7 Pro x32) ? Could be important for George to know, because that would mean my different dpi settings are not the cause (unless you use non default dpi settings too).
--
Johan

Adrian Buehlmann

unread,
Jun 22, 2010, 3:12:51 AM6/22/10
to thg...@googlegroups.com
On 22.06.2010 08:45, Johan Samyn wrote:
> 2010/6/22 Adrian Buehlmann <adr...@cadifra.com <mailto:adr...@cadifra.com>>

I think the font of the log column is smaller with 7dd3ffb36a69 compared
to 5592d07c28c3.

See attached screenshot, done with 5592d07c28c3 on Windows 7 (same
Windows install as before).

I do not have a custom DPI text size. In other words: my DPI should be
default (see DPI-Capture.PNG)


Capture-5592d07c28c3.PNG
DPI-Capture.PNG

David Wilhelm

unread,
Jun 25, 2010, 2:10:53 PM6/25/10
to thg...@googlegroups.com
On Mon, Jun 21, 2010 at 08:54:03PM +0100, George Marrows wrote:
> More screenshots always welcome.

Nothing new here, just a couple more data points.

The attached is from xubuntu. Server 2003 looks almost exactly the same.

thg_log_color.png

Yuya Nishihara

unread,
Jun 26, 2010, 6:04:31 AM6/26/10
to thg...@googlegroups.com
Patches to solve remaining issues:

- selected text not drawn in white.

As a side-effect, tag text on selected row becomes hard to read.
Maybe we need to set foreground-color for it.

- the text is slightly lower than the other columns.

With this patch, log text will be placed *mostly* on the same line.

According to some experiments, there're difference in calculation
of text height between standard QTableView item and QTextDocument.
At least, it depends on font.

It works perfectly on Windows, but isn't on Linux.
Anyway it doesn't make things worse.

Yuya,

Yuya Nishihara

unread,
Jun 26, 2010, 6:04:33 AM6/26/10
to thg...@googlegroups.com
# HG changeset patch
# User Yuya Nishihara <yu...@tcha.org>
# Date 1277543929 -32400
# Node ID df32a7a18287477de332d73c21ba1dadfdc41f6a
# Parent 9dece01c85ee2a0ff18e20d9bf735ec48fd74703
htmllistview: respect selection color for text

This makes hard to read selected tag text. Maybe tag text needs to set
foreground color explicitly.

diff --git a/tortoisehg/hgqt/htmllistview.py b/tortoisehg/hgqt/htmllistview.py
--- a/tortoisehg/hgqt/htmllistview.py
+++ b/tortoisehg/hgqt/htmllistview.py

@@ -107,7 +107,11 @@ class HTMLDelegate(QStyledItemDelegate):
painter.translate(QPointF(
option.rect.left(),
option.rect.top() + (option.rect.height() - doc.size().height()) / 2))
- doc.drawContents(painter)
+ ctx = QAbstractTextDocumentLayout.PaintContext()
+ if option.state & QStyle.State_Selected:
+ ctx.palette.setColor(QPalette.Text,
+ option.palette.color(QPalette.HighlightedText))
+ doc.documentLayout().draw(painter, ctx)
painter.restore()

def sizeHint(self, option, index):

Yuya Nishihara

unread,
Jun 26, 2010, 6:04:32 AM6/26/10
to thg...@googlegroups.com
# HG changeset patch
# User Yuya Nishihara <yu...@tcha.org>
# Date 1277542502 -32400
# Node ID 9dece01c85ee2a0ff18e20d9bf735ec48fd74703
# Parent c4c9cc7f8f4563e5a664f7f317f87499f914e8b3
htmllistview: place text at vertically center

diff --git a/tortoisehg/hgqt/htmllistview.py b/tortoisehg/hgqt/htmllistview.py
--- a/tortoisehg/hgqt/htmllistview.py
+++ b/tortoisehg/hgqt/htmllistview.py

@@ -104,7 +104,9 @@ class HTMLDelegate(QStyledItemDelegate):
painter.save()
doc.setHtml(text)
painter.setClipRect(option.rect)
- painter.translate(option.rect.topLeft())
+ painter.translate(QPointF(
+ option.rect.left(),
+ option.rect.top() + (option.rect.height() - doc.size().height()) / 2))
doc.drawContents(painter)
painter.restore()

Yuya Nishihara

unread,
Jun 27, 2010, 10:57:49 AM6/27/10
to thg...@googlegroups.com
Yuya Nishihara wrote:
> Patches to solve remaining issues:
>
> - selected text not drawn in white.
> - the text is slightly lower than the other columns.
>
...

> It works perfectly on Windows, but isn't on Linux.
> Anyway it doesn't make things worse.

Test passed on Mac, so I pushed as 4ccbe35696af and 9354c9fa9b25.
If you found strange behavior, could you report it?, please.

Yuya,

Steve Borho

unread,
Jun 28, 2010, 1:28:37 PM6/28/10
to thg...@googlegroups.com

Looks fine on Linux here (Gnome on Ubuntu)

--
Steve Borho

Johan Samyn

unread,
Jun 28, 2010, 3:34:45 PM6/28/10
to thg...@googlegroups.com
2010/6/27 Yuya Nishihara <yu...@tcha.org>
Hi,
As you already pointed out in your commit message for cset 9354c9fa9b25, tag text is not rendered as it should.
I also notice the log message (and tags) of the selected row stays white text when focus is removed from the changelog pane, into the filelist pane for example.
See attached screendump, taken on Win7.
-- Johan

TortoiseHg_Workbench_white-log-msg.png
TortoiseHg Workbench_hard-to-read-tag.png

Steve Borho

unread,
Jun 28, 2010, 3:40:36 PM6/28/10
to thg...@googlegroups.com

Setting the foreground color of the tag format is trivial, just add
'black' to the log.tag style in qtlib.py (and do the same for
log.patch and log.branch while you are in there).


--
Steve Borho

Yuya Nishihara

unread,
Jun 29, 2010, 12:30:13 PM6/29/10
to thg...@googlegroups.com

Thanks. The first problem will be solved by Steve's suggestion.
Maybe I or somebody will post the patch later.

Second one, which Johan pointed out, looks hard. I didn't notice it because
in my environment, background color isn't changed on focus out.
I'd better look through it more deeply.

Yuya Nishihara

unread,
Jun 29, 2010, 12:50:44 PM6/29/10
to thg...@googlegroups.com

Ah, got it. 1fd72cc0e735 will fix the latter.

Yuya,

Steve Borho

unread,
Jun 29, 2010, 1:50:14 PM6/29/10
to thg...@googlegroups.com

I went ahead and pushed the foreground label colors. Are we happy
with these results now? Looks good on Windows 7 here.

--
Steve Borho

Yuya Nishihara

unread,
Jun 30, 2010, 10:24:57 AM6/30/10
to thg...@googlegroups.com
Steve Borho wrote:
> On Tue, Jun 29, 2010 at 11:50 AM, Yuya Nishihara <yu...@tcha.org> wrote:
> > Yuya Nishihara wrote:
> >> Steve Borho wrote:
...

> >> > Setting the foreground color of the tag format is trivial, just add
> >> > 'black' to the log.tag style in qtlib.py (and do the same for
> >> > log.patch and log.branch while you are in there).
> >>
> >> Thanks. The first problem will be solved by Steve's suggestion.
> >> Maybe I or somebody will post the patch later.
> >>
> >> Second one, which Johan pointed out, looks hard. I didn't notice it because
> >> in my environment, background color isn't changed on focus out.
> >> I'd better look through it more deeply.
> >
> > Ah, got it. 1fd72cc0e735 will fix the latter.
>
> I went ahead and pushed the foreground label colors. Are we happy
> with these results now? Looks good on Windows 7 here.

Looks pretty good on Linux/KDE.
Thanks!

Yuya Nishihara

unread,
Jul 1, 2010, 12:37:56 PM7/1/10
to thg...@googlegroups.com
Johan Samyn wrote:
> Just one thing, I may have mentioned earlier, but I'm not sure. What could
> be the reason the log text is always shown in a smaller font ? At least on
> Win7.

Does the attached patch make a difference?
If so, I'll tackle it more seriously.

Yuya,

htmllistview-qlabel-delegate.diff

George Marrows

unread,
Jul 1, 2010, 4:18:27 PM7/1/10
to thg...@googlegroups.com
Johan said about Yuya's work onlog selection rendering:
> Yes, on Win7 too, thanks. Great job.

And thanks from me too. On Vista the log now looks perfect whether selected or
unselected, focused or unfocused.

Unfortunately grep doesn't like right yet - see forthcoming screenshot. The issue is
that the part drawn by the delegate looks like it does in the log, but the part drawn
by the widget is more the native Vista look and feel - the transparent bar with slight
rounding is also used in Explorer for example. There's also an effect of paler
highlighting of the row that the mouse is hovering over.

The reason is that the log is a QTableView, but grep uses QTreeView. The following patch
changes grep to use QTableView. If people are happy with it, I'll tidy it up to size
columns correctly.

There's an unconnected bug with right click | View File - looking at that next.

-- George

George Marrows

unread,
Jul 1, 2010, 4:18:28 PM7/1/10
to thg...@googlegroups.com
# HG changeset patch
# User George Marrows
# Date 1278014944 -3600
# Node ID 9ceace4e0ecee31a8f67b493fbc96f055f99f55a
# Parent fe55c42e746b02174733a79dfcd65e97ae1ca78f
grep: convert to QTableView

On Vista QTreeView renders selections using Vista-style transparent
curved-effect bars. The QItemDelegate we use to draw the Match Text
column can't currently render these bars. So we switch to QTableView
which renders selections more simply.

diff --git a/tortoisehg/hgqt/grep.py b/tortoisehg/hgqt/grep.py
--- a/tortoisehg/hgqt/grep.py
+++ b/tortoisehg/hgqt/grep.py
@@ -119,8 +119,6 @@
mainvbox.addWidget(frame)

tv = MatchTree(repo, self)
- tv.setItemsExpandable(False)
- tv.setRootIsDecorated(False)
tm = MatchModel(self)
tv.setModel(tm)
tv.setColumnHidden(COL_REVISION, True)
@@ -342,14 +340,20 @@
COL_USER = 3 # Hidden if ctx
COL_TEXT = 4

-class MatchTree(QTreeView):
+class MatchTree(QTableView):
def __init__(self, repo, parent=None):
- QTreeView.__init__(self, parent)
+ QTableView.__init__(self, parent)
self.repo = repo
self.delegate = htmllistview.HTMLDelegate(self)
self.setItemDelegateForColumn(COL_TEXT, self.delegate)
- self.setSelectionMode(QTreeView.ExtendedSelection)
+ self.setSelectionMode(QTableView.ExtendedSelection)
+ self.setSelectionBehavior(QAbstractItemView.SelectRows)
self.setContextMenuPolicy(Qt.CustomContextMenu)
+ self.setShowGrid(False)
+ vh = self.verticalHeader()
+ vh.hide()
+ vh.setDefaultSectionSize(20)
+
self.connect(self, SIGNAL('customContextMenuRequested(const QPoint &)'),
self.customContextMenuRequested)
self.pattern = None
@@ -383,17 +387,17 @@
def mousePressEvent(self, event):
self.pressPos = event.pos()
self.pressTime = QTime.currentTime()
- return QTreeView.mousePressEvent(self, event)
+ return QTableView.mousePressEvent(self, event)

def mouseMoveEvent(self, event):
d = event.pos() - self.pressPos
if d.manhattanLength() < QApplication.startDragDistance():
- return QTreeView.mouseMoveEvent(self, event)
+ return QTableView.mouseMoveEvent(self, event)
elapsed = self.pressTime.msecsTo(QTime.currentTime())
if elapsed < QApplication.startDragTime():
- return QTreeView.mouseMoveEvent(self, event)
+ return QTableView.mouseMoveEvent(self, event)
self.dragObject()
- return QTreeView.mouseMoveEvent(self, event)
+ return QTableView.mouseMoveEvent(self, event)

def customContextMenuRequested(self, point):
selrows = []

George Marrows

unread,
Jul 1, 2010, 4:20:05 PM7/1/10
to thg...@googlegroups.com
The promised screenshot..
grep.png

Steve Borho

unread,
Jul 1, 2010, 4:34:25 PM7/1/10
to thg...@googlegroups.com
On Thu, Jul 1, 2010 at 3:18 PM, George Marrows
<george....@googlemail.com> wrote:
> Johan said about Yuya's work onlog selection rendering:
>> Yes, on Win7 too, thanks. Great job.
>
> And thanks from me too. On Vista the log now looks perfect whether selected or
> unselected, focused or unfocused.
>
> Unfortunately grep doesn't like right yet - see forthcoming screenshot. The issue is
> that the part drawn by the delegate looks like it does in the log, but the part drawn
> by the widget is more the native Vista look and feel - the transparent bar with slight
> rounding is also used in Explorer for example. There's also an effect of paler
> highlighting of the row that the mouse is hovering over.
>
> The reason is that the log is a QTableView, but grep uses QTreeView. The following patch
> changes grep to use QTableView. If people are happy with it, I'll tidy it up to size
> columns correctly.

I'm not wed to a QTreeView by any means, feel free to use another
widget if it works better.

--
Steve Borho

Steve Borho

unread,
Jul 1, 2010, 4:38:15 PM7/1/10
to thg...@googlegroups.com
On Thu, Jul 1, 2010 at 3:18 PM, George Marrows
<george....@googlemail.com> wrote:
> # HG changeset patch
> # User George Marrows
> # Date 1278014944 -3600
> # Node ID 9ceace4e0ecee31a8f67b493fbc96f055f99f55a
> # Parent  fe55c42e746b02174733a79dfcd65e97ae1ca78f
> grep: convert to QTableView
>
> On Vista QTreeView renders selections using Vista-style transparent
> curved-effect bars. The QItemDelegate we use to draw the Match Text
> column can't currently render these bars. So we switch to QTableView
> which renders selections more simply.

This is an improvement, so pushed.

--
Steve Borho

Reply all
Reply to author
Forward
0 new messages