<?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[How to refuse that user select item by Mouse drag?]]></title><description><![CDATA[<p dir="auto">QTableView</p>
<p dir="auto">When user press mouse (LeftButton) int QModelIndex (0,0), then move mouse to QModelIndex (0, 5), and release mouse at this QModelIndex (0, 5).</p>
<p dir="auto">Now there are six items are selected, and there items's background-color are changed (white -&gt; blue)</p>
<p dir="auto">How to refuse this function?  In other words,when user do it ,QTableView will reset the background-color of thses item,but i had set the background-color ( by QItemDelegate ), and it will lead my set to invaild.</p>
]]></description><link>https://forum.qt.io/topic/163068/how-to-refuse-that-user-select-item-by-mouse-drag</link><generator>RSS for Node</generator><lastBuildDate>Sun, 06 Sep 2026 10:29:18 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/163068.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Aug 2025 09:44:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to How to refuse that user select item by Mouse drag? on Tue, 26 Aug 2025 07:06:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qazaq408">@<bdi>qazaq408</bdi></a><br />
I am afraid I do not understand what you are saying/what you are trying to achieve.</p>
<p dir="auto">Meanwhile, just for the code you show what is <code>painer-&gt;stroe()</code> at the start, and why do you have a  <code>painter-&gt;save()</code> at the end?  Normally you save painter state at the start of your code and restore it at the end, if anything you seem to be doing the opposite?</p>
]]></description><link>https://forum.qt.io/post/830871</link><guid isPermaLink="true">https://forum.qt.io/post/830871</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 26 Aug 2025 07:06:05 GMT</pubDate></item><item><title><![CDATA[Reply to How to refuse that user select item by Mouse drag? on Wed, 27 Aug 2025 06:41:12 GMT]]></title><description><![CDATA[<p dir="auto">I guess you need to set the selection mode: <a href="https://doc.qt.io/qt-6/qabstractitemview.html#SelectionMode-enum" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/qabstractitemview.html#SelectionMode-enum</a></p>
<p dir="auto">Pick one that works for you.</p>
]]></description><link>https://forum.qt.io/post/830916</link><guid isPermaLink="true">https://forum.qt.io/post/830916</guid><dc:creator><![CDATA[SimonSchroeder]]></dc:creator><pubDate>Wed, 27 Aug 2025 06:41:12 GMT</pubDate></item><item><title><![CDATA[Reply to How to refuse that user select item by Mouse drag? on Tue, 26 Aug 2025 07:06:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qazaq408">@<bdi>qazaq408</bdi></a><br />
I am afraid I do not understand what you are saying/what you are trying to achieve.</p>
<p dir="auto">Meanwhile, just for the code you show what is <code>painer-&gt;stroe()</code> at the start, and why do you have a  <code>painter-&gt;save()</code> at the end?  Normally you save painter state at the start of your code and restore it at the end, if anything you seem to be doing the opposite?</p>
]]></description><link>https://forum.qt.io/post/830871</link><guid isPermaLink="true">https://forum.qt.io/post/830871</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 26 Aug 2025 07:06:05 GMT</pubDate></item><item><title><![CDATA[Reply to How to refuse that user select item by Mouse drag? on Tue, 26 Aug 2025 01:25:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a></p>
<p dir="auto">The first, thank you answer.</p>
<p dir="auto">But there are some exception. For instance, a column has a QItemDelegate,it likes</p>
<pre><code class="language-c++">void NameDelegate(QPainter* painer, const QStyleOptionVitwItem&amp; op, const QModelIndex&amp; modelindex)const {
    painer-&gt;stroe();
    //draw rect for some kind of important tip
    painter-&gt;fillRect(op.x()  + 2, 
                    op.y() + 2, 
                    op.width() - 4,
                    op.height() - 4,
                    QBrush(QColor(Qt::yellow);

    //draw name text
    QString name = index-&gt;model()-&gt;data(Qt::DisplayRole).toString();
    QRect txtRect(op.x()  + 4,op.y() + 4, op.width() - 8,op.height() - 8);
    painter-&gt;drawText(txtRect, Qt::AlignCenter, name);

    painter-&gt;save();
}
                                    
</code></pre>
<p dir="auto">A column set this NameDelegate (Inherits QItemDelegate), if i use QSS,like selection-color,it will lead all background-color of this NAME column change to white,but as you see, i need this colum show some special background-color( a Rect but don't fill full item)</p>
<p dir="auto">So do you have any better ideas?</p>
]]></description><link>https://forum.qt.io/post/830863</link><guid isPermaLink="true">https://forum.qt.io/post/830863</guid><dc:creator><![CDATA[qazaq408]]></dc:creator><pubDate>Tue, 26 Aug 2025 01:25:50 GMT</pubDate></item><item><title><![CDATA[Reply to How to refuse that user select item by Mouse drag? on Mon, 25 Aug 2025 10:04:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/qazaq408">@<bdi>qazaq408</bdi></a><br />
What about doing it via stylesheet, <a href="https://doc.qt.io/qt-6/stylesheet-reference.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/stylesheet-reference.html</a> ?</p>
<blockquote>
<p dir="auto">QTableView</p>
<p dir="auto">The color and background of the selected item is styled using selection-color and selection-background-color respectively.</p>
</blockquote>
<p dir="auto">E.g. <a href="https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qtableview" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-6/stylesheet-examples.html#customizing-qtableview</a></p>
<pre><code>QTableView {
    selection-background-color: ...
}
</code></pre>
<p dir="auto">Otherwise probably need to see your code.</p>
]]></description><link>https://forum.qt.io/post/830843</link><guid isPermaLink="true">https://forum.qt.io/post/830843</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Mon, 25 Aug 2025 10:04:12 GMT</pubDate></item></channel></rss>