<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Selection highlight is a thin blue bar at the left of the cell.]]></title><description><![CDATA[<p dir="auto">I'm a relative beginner with Qt.</p>
<p dir="auto">I've set up a QTableView with a QAbstractTableModel subclass, and have it working except for the selection highlight, which is just a thin blue vertical line at the left of the cells.</p>
<p dir="auto">Google (possibly hallucinating) tells me I need to have the model's <code>data()</code> method handle <code>SizeHintRole</code>, but that requires the view to pass its fontMetrics to the model, and then the model must calculate the text size,  I don't understand why the model needs to be responsible for  worrying about pixels.   I've read the page about why the model specifies <em>some</em> formatting that is really intrinsic to the data, so it can be rendered consistently in multiple views.  But even that seems like excessive coupling and blurring of the Single Responsibility principle.</p>
<p dir="auto">I'm not sure why the model should have to calculate the text size just so the view can highlight it, especially when SizeToContents already did that nicely.  This seems redundant.</p>
<h1>Question</h1>
<p dir="auto">Is Google just hallucinating, and is there a way to make the view use the already (internally) calculated text size for selection highlighting? Or, is the only recourse to create a delegate and re-do the text size calculation there?</p>
<p dir="auto">Thanks</p>
]]></description><link>https://forum.qt.io/topic/165156/selection-highlight-is-a-thin-blue-bar-at-the-left-of-the-cell.</link><generator>RSS for Node</generator><lastBuildDate>Wed, 14 Oct 2026 04:29:04 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165156.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 08 Oct 2026 00:08:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Mon, 12 Oct 2026 13:06:52 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jim-g">@<bdi>Jim-G</bdi></a> said in <a href="/post/840408">Selection highlight is a thin blue bar at the left of the cell.</a>:</p>
<blockquote>
<p dir="auto">So why does setting alternatingRowColors cause the change in highlight?</p>
</blockquote>
<p dir="auto">Qt tries to use the OS default widgets first. Alternating row colors is not supported by the OS directly. So, Qt will draw it from scratch and usually tries to mimic the OS look. Seems like it did not get updated, yet.</p>
]]></description><link>https://forum.qt.io/post/840453</link><guid isPermaLink="true">https://forum.qt.io/post/840453</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Mon, 12 Oct 2026 13:06:52 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Sat, 10 Oct 2026 06:50:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jim-g">@<bdi>Jim-G</bdi></a> said in <a href="/post/840408">Selection highlight is a thin blue bar at the left of the cell.</a>:</p>
<blockquote>
<p dir="auto">So why does setting alternatingRowColors cause the change in highlight? Is that a bug?</p>
</blockquote>
<p dir="auto">The WinUI3 style has no information about alternating row colors so this is the solution for this.</p>
<blockquote>
<p dir="auto">med up against the left side of the text with no intervening space</p>
</blockquote>
<p dir="auto">This will be fixed</p>
]]></description><link>https://forum.qt.io/post/840413</link><guid isPermaLink="true">https://forum.qt.io/post/840413</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Sat, 10 Oct 2026 06:50:50 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 23:24:44 GMT]]></title><description><![CDATA[<p dir="auto">Also, what I see differs markedly from the example of winui 3 selection you cite. My selection indicators are only 2 pixels wide and jammed up against the left side of the text with no intervening space... actually they overlap (under) the leftmost pixel column of the text.</p>
]]></description><link>https://forum.qt.io/post/840410</link><guid isPermaLink="true">https://forum.qt.io/post/840410</guid><dc:creator><![CDATA[Jim G]]></dc:creator><pubDate>Fri, 09 Oct 2026 23:24:44 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 21:32:29 GMT]]></title><description><![CDATA[<p dir="auto">So why does setting <code>alternatingRowColors</code> cause the change in highlight? Is that a bug?</p>
<p dir="auto">I'm not trying to be difficult.  I'm still learning Qt/PySide6 (excellent tools IMO) and am puzzled by the need to set <code>alternatingRowColors</code> just to get the expected highlight behavior.</p>
]]></description><link>https://forum.qt.io/post/840408</link><guid isPermaLink="true">https://forum.qt.io/post/840408</guid><dc:creator><![CDATA[Jim G]]></dc:creator><pubDate>Fri, 09 Oct 2026 21:32:29 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 20:11:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jim-g">@<bdi>Jim-G</bdi></a> said in <a href="/post/840406">Selection highlight is a thin blue bar at the left of the cell.</a>:</p>
<blockquote>
<p dir="auto">Notice the "selection" highlight in the second screenshot is just a thin blue line at the left of each cell.</p>
</blockquote>
<p dir="auto">And that's the correct winui3 style.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/28016b3c-3114-4583-a6f1-164ce4381f6a.png" alt="3d371abe-a5a4-4328-ae54-9f9e0395d0d7-grafik.png" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/840407</link><guid isPermaLink="true">https://forum.qt.io/post/840407</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 09 Oct 2026 20:11:51 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 20:10:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/christian-ehrlicher">@<bdi>Christian-Ehrlicher</bdi></a> said in <a href="/post/840405">Selection highlight is a thin blue bar at the left of the cell.</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jim-g">@<bdi>Jim-G</bdi></a> said in <a href="/post/840404">Selection highlight is a thin blue bar at the left of the cell.</a>:</p>
<blockquote>
<p dir="auto">Bug?</p>
</blockquote>
<p dir="auto">No, it's the default WinUI 3 style. Look into your explorer to see that the highlight is gray.</p>
</blockquote>
<p dir="auto">I'm not following. I think we're talking about two different things.  I can reproduce the issue using the sample code only.</p>
<p dir="auto">Here's the UI including <code>self.table_view.setAlternatingRowColors(True)</code> and line 4 selected:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/7e0a1d5e-3d96-44ec-812a-fe264debdbbf.PNG" alt="2026-10-09_12-50-31.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">And now with that single line commented out and line 3 selected:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/187d5350-b685-4e1c-922f-72014c262c28.PNG" alt="2026-10-09_13-06-02.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">Notice the "selection" highlight in the second screenshot is just a thin blue line at the left of each cell.</p>
<p dir="auto">It is unexpected that displaying the correct highlighting would involve the setting of <code>alternatingRowColors</code>.</p>
]]></description><link>https://forum.qt.io/post/840406</link><guid isPermaLink="true">https://forum.qt.io/post/840406</guid><dc:creator><![CDATA[Jim G]]></dc:creator><pubDate>Fri, 09 Oct 2026 20:10:08 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 20:04:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jim-g">@<bdi>Jim-G</bdi></a> said in <a href="/post/840404">Selection highlight is a thin blue bar at the left of the cell.</a>:</p>
<blockquote>
<p dir="auto">Bug?</p>
</blockquote>
<p dir="auto">No, it's the default WinUI 3 style.</p>
]]></description><link>https://forum.qt.io/post/840405</link><guid isPermaLink="true">https://forum.qt.io/post/840405</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Fri, 09 Oct 2026 20:04:12 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 20:00:34 GMT]]></title><description><![CDATA[<p dir="auto">OK, I think I found a bug.  I closely examined some sample code I found that uses a <code>QStandardItemModel</code>, and displays selection highlights correctly.  Here's a screenshot:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/ff384c0a-79da-4597-9aec-c9e6e0922087.PNG" alt="2026-10-09_12-50-31.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">Other than the change of model class, the only other difference I could find was that in the sample code there is this:</p>
<pre><code>        # Alternating row colors for data density scannability
        self.table_view.setAlternatingRowColors(True)
</code></pre>
<p dir="auto">So I tried adding that to my code, and it fixed the issue:</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/034d82c9-59a0-47c3-8180-1e9d2413fcd8.PNG" alt="2026-10-09_12-53-11.PNG" class=" img-fluid img-markdown" /></p>
<p dir="auto">Bug?</p>
<p dir="auto">Also note that in my earlier screenshot showing the problem, there is already alternate row highlighting which is unexpected as the default for <code>alternatingRowColors</code> is <code>False</code>.  Something's amiss here.</p>
]]></description><link>https://forum.qt.io/post/840404</link><guid isPermaLink="true">https://forum.qt.io/post/840404</guid><dc:creator><![CDATA[Jim G]]></dc:creator><pubDate>Fri, 09 Oct 2026 20:00:34 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 19:10:41 GMT]]></title><description><![CDATA[<p dir="auto">In C++ you return a default <code>QVariant()</code> for default behavior.  In PySide6 this maps to <code>None</code>, and <code>QVariant</code> is not even defined or available for use.  Also, in PySide6 <code>QAbstractItemModel.data()</code> is virtual with no default implementation.</p>
<p dir="auto">Using <code>return super().data(index,role)</code> raises <code>NotImplementedError</code> as expected</p>
]]></description><link>https://forum.qt.io/post/840403</link><guid isPermaLink="true">https://forum.qt.io/post/840403</guid><dc:creator><![CDATA[Jim G]]></dc:creator><pubDate>Fri, 09 Oct 2026 19:10:41 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 18:52:27 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/simonschroeder">@<bdi>SimonSchroeder</bdi></a> said in <a href="/post/840400">Selection highlight is a thin blue bar at the left of the cell.</a>:</p>
<blockquote>
<p dir="auto">You <code>data</code> method only returns something for the few roles you have specified. Otherwise you are returning <code>None</code>. Try instead to return <code>QAbstractItemModel.data(...)</code> (I don't know Python and can't tell you how to exactly write that). This might solve your problem, but I'm not sure.</p>
</blockquote>
<pre><code>    return super().data(index, role)
</code></pre>
]]></description><link>https://forum.qt.io/post/840402</link><guid isPermaLink="true">https://forum.qt.io/post/840402</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 09 Oct 2026 18:52:27 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Fri, 09 Oct 2026 07:08:17 GMT]]></title><description><![CDATA[<p dir="auto">You <code>data</code> method only returns something for the few roles you have specified. Otherwise you are returning <code>None</code>. Try instead to return <code>QAbstractItemModel.data(...)</code> (I don't know Python and can't tell you how to exactly write that). This might solve your problem, but I'm not sure.</p>
]]></description><link>https://forum.qt.io/post/840400</link><guid isPermaLink="true">https://forum.qt.io/post/840400</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Fri, 09 Oct 2026 07:08:17 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Thu, 08 Oct 2026 23:19:53 GMT]]></title><description><![CDATA[<p dir="auto">The <code>flags()</code> question was interesting, but the default is <code>ItemIsSelectable|ItemIsEnabled</code>, and implementing <code>flags()</code> returning those values had no effect.</p>
<p dir="auto">I tried some sample code using <code>QTableWidget</code>, and that works correctly.  I then made sure my code sets all the same attributes on the view and the model, with no effect.  I'm stumped.  I guess I'm going to have to reimplement my code with <code>QTableWidget</code> and see what happens.</p>
<p dir="auto">More later...</p>
]]></description><link>https://forum.qt.io/post/840398</link><guid isPermaLink="true">https://forum.qt.io/post/840398</guid><dc:creator><![CDATA[Jim G]]></dc:creator><pubDate>Thu, 08 Oct 2026 23:19:53 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Thu, 08 Oct 2026 13:41:00 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jim-g">@<bdi>Jim-G</bdi></a><br />
Hi.  I am travelling abroad so cannot try anything.</p>
<p dir="auto">As ever with this sort of thing, try to reduce to minimal and then build up.</p>
<p dir="auto">I don't recall ever having a problem with selection highlighting nor doing anything at all about font, font metrics or sizes.  If I were you I would:</p>
<ul>
<li>
<p dir="auto">Temporarily try a <code>QTableWidget</code>.  Put in a couple of fixed rows and a couple of columns.  Try a couple of <code>SelectionBehaviour</code>s.  Works or looks odd?</p>
</li>
<li>
<p dir="auto">Move to a <code>QTreeView</code> but try a <code>QStandardItemModel</code> for the model.  Again put in a couple of rows and columns.  How does selection look?</p>
</li>
</ul>
<p dir="auto">If problems there that is one thing.  If they work but yours does not then start looking at your implementation.</p>
<p dir="auto">P.S.<br />
Is your issue because you did not implement the <code>flags()</code> override?  You may need to do that for a <code>QAbstractTableModel</code>.  You need to return at least <code>ItemIsSelectable</code>: because you have not I wonder of your items are just not selectable so it won't show properly?  Check what your current <code>SAEventsModel.flags(index)</code> is returning.  It actually ought be correct without override, but just verify.</p>
]]></description><link>https://forum.qt.io/post/840394</link><guid isPermaLink="true">https://forum.qt.io/post/840394</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Thu, 08 Oct 2026 13:41:00 GMT</pubDate></item><item><title><![CDATA[Reply to Selection highlight is a thin blue bar at the left of the cell. on Thu, 08 Oct 2026 00:37:17 GMT]]></title><description><![CDATA[<p dir="auto">I implemented Google's suggestion, but it has no effect.  Here's the interesting part of the code:</p>
<h2>QAbstractTableModel Subclass</h2>
<pre><code>class ColDef:
    ''' 
        Store column definitions for a model
        
        Still a work-in-progress 
    '''
    def __init__(self, header:str, attr:str, fmt:str, align:Qt.AlignmentFlag):
        self.header = header
        self.attr   = attr
        self.fmt    = fmt
        self.align  = align
        
    def format(self, row) -&gt; str:
        if self.attr == '': return ''
        val = getattr(row, self.attr)
        
        if self.fmt == 'time':
            if isinstance(val, dt.datetime):
                return val.strftime("%H:%M")
        else: # For now...
            return str(val)
        
        return None

columnDefs = [
    #       Header              Field in rowset                 Format  Alignment
    #       ------------------  ------------------------------  ------- ---------------
    ColDef('Scheduled\nStart', 'start_ts',                      'time', Qt.AlignCenter),
    ColDef('Scheduled\nEnd',   'end_ts',                        'time', Qt.AlignCenter),
    ColDef('Leader',           '',                              '',     Qt.AlignLeft),
    ColDef('Actual\nStart',    '',                              '',     Qt.AlignCenter),
    ColDef('Actual\nEnd',      '',                              '',     Qt.AlignCenter),
    ColDef('Activity',         '',                              '',     Qt.AlignCenter),
    ColDef('Description',      'title',                         '',     Qt.AlignLeft),
    ColDef('Limit',            'registrations_limit',           'int',  Qt.AlignCenter),
    ColDef('Reg',              'confirmed_registrations_count', 'int',  Qt.AlignCenter),
    ColDef('Wait',             'waitlist_registration_count',   'int',  Qt.AlignCenter),
]

class SAEventsModel(QAbstractTableModel):
    def __init__(self, parent=None, * , dbEngine):
        super().__init__()
        
        self.dbEngine = dbEngine
        self.rowset   = []
        self.fontMetrics = None

    def setFontMetrics(self, font:QFont):
        self.fontMetrics = QFontMetrics(font)

    def refresh(self, d:dt.date):
        self.beginResetModel()
        
        with Session(self.dbEngine) as dbSession:
            stmt = select(DVEventSession)\
                    .where(DVEventSession.event_date==d)\
                    .order_by(DVEventSession.start_ts)
            self.rowset = dbSession.scalars(stmt).all()
            
        self.endResetModel()

    def headerData(self, section:int, orientation:Qt.Orientation, role:Qt.ItemDataRole):
        if orientation == Qt.Orientation.Horizontal \
                and 0 &lt;= section &lt; len(columnDefs) \
                and role == Qt.DisplayRole:
            return columnDefs[section].header
        return None

    def rowCount(self, _) -&gt; int:
        return len(self.rowset)

    def columnCount(self, _) -&gt; int:
        return len(columnDefs)
    
    def data(self, index:QModelIndex, role:Qt.ItemDataRole):
        if index.isValid():
            row = index.row()
            col = index.column()
            cd = columnDefs[col]
            
            if role in (Qt.ItemDataRole.DisplayRole, Qt.ItemDataRole.EditRole):
                # Table is read-only, return same data for Display and Edit
                return cd.format(self.rowset[row])
            
            elif role == Qt.ItemDataRole.SizeHintRole:
                # Recalculate the text size 
                text = cd.format(self.rowset[row])
                w    = self.fontMetrics.horizontalAdvance(text)
                h    = self.fontMetrics.height()
                return QSize(w+20, h+10)
            
            elif role == Qt.ItemDataRole.TextAlignmentRole:
                # Return the desired alignment
                return cd.align
            
        return None
</code></pre>
<h2>Main Window snippet</h2>
<p dir="auto"><code>self.ui</code> is loaded from a QtCreator-generated <code>.ui</code> file.  <code>self.ui.guildEvents' is a </code>QTableView`</p>
<pre><code>        td = dt.date.today()
        self.ui.curDate.setText(f"{td:%B} {td.day} {td:%Y}")
        
        self.model = SAEventsModel(dbEngine=dbEngine)
        self.model.refresh(td)
        self.model.setFontMetrics(self.ui.guildEvents.font())
        
        self.ui.guildEvents.setModel(self.model)
        self.ui.guildEvents.horizontalHeader().setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents)
        self.ui.guildEvents.setSelectionBehavior(qv.SelectionBehavior.SelectRows)
</code></pre>
<h2>Main Window Display</h2>
<p dir="auto">The middle row is selected.</p>
<p dir="auto"><img src="https://ddgobkiprc33d.cloudfront.net/f2a96f52-114c-4da5-9f06-ac9df814d4f0.PNG" alt="2026-10-07_17-35-57.PNG" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.qt.io/post/840392</link><guid isPermaLink="true">https://forum.qt.io/post/840392</guid><dc:creator><![CDATA[Jim G]]></dc:creator><pubDate>Thu, 08 Oct 2026 00:37:17 GMT</pubDate></item></channel></rss>