<?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[Searching a QTable widget items using wild cards!]]></title><description><![CDATA[<p dir="auto">IN my qt c++ application I have several items in a qtablewidget. A lineedit along with a button is used by me inorder to search the qtablewidget when a particular word is given to the line edit and the search button is clicked! FOllowing is my code!</p>
<pre><code class="language-cpp">bool found=false;
    QString Line= ui-&gt;search-&gt;text();

    for(int i=0;i&lt;100;i++){
        if(ui-&gt;tableWidget-&gt;item(i,0)-&gt;text()== Line){
            found = true;
            break;
        }
    }
    if(found){
        ui-&gt;tableWidget-&gt;clear();
        ui-&gt;tableWidget-&gt;setItem(0,0,new QTableWidgetItem(Line));
    }
    else{
        QMessageBox::warning(this, tr("Application Name"), tr("The word you are searching does not exist!") );
}
</code></pre>
<p dir="auto">This code works if an exact word in the table widget is given but if I use</p>
<p dir="auto">ui-&gt;tableWidget-&gt;item(i,0)-&gt;text()=="%"+ Line+"%"</p>
<p dir="auto">it won't work for the wild card scenario so that I can search even part of a word is given! How can I correct this issue?</p>
]]></description><link>https://forum.qt.io/topic/84273/searching-a-qtable-widget-items-using-wild-cards</link><generator>RSS for Node</generator><lastBuildDate>Tue, 17 Nov 2026 23:12:22 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/84273.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 18 Oct 2017 02:11:31 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Searching a QTable widget items using wild cards! on Wed, 18 Oct 2017 07:43:38 GMT]]></title><description><![CDATA[<ol>
<li>separate <code>QTableWidget</code> into a <code>QTableView</code> and a <code>QStandardItemModel</code></li>
<li>add a <code>QSortFilterProxyModel</code> as the model of <code>QTableView</code> and set the <code>QStandardItemModel</code> as the <code>QSortFilterProxyModel</code>'s <code>sourceModel</code></li>
<li>call <code>QSortFilterProxyModel::setFilterWildcard</code> or <code>QSortFilterProxyModel::setFilterRegExp</code> to perform the searching</li>
</ol>
<p dir="auto">See <a href="http://doc.qt.io/qt-5/qtwidgets-itemviews-basicsortfiltermodel-example.html" target="_blank" rel="noopener noreferrer nofollow ugc">Basic Sort/Filter Model Example</a></p>
]]></description><link>https://forum.qt.io/post/421500</link><guid isPermaLink="true">https://forum.qt.io/post/421500</guid><dc:creator><![CDATA[VRonin]]></dc:creator><pubDate>Wed, 18 Oct 2017 07:43:38 GMT</pubDate></item><item><title><![CDATA[Reply to Searching a QTable widget items using wild cards! on Wed, 18 Oct 2017 03:05:49 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/lasith">@<bdi>Lasith</bdi></a></p>
<p dir="auto">You can use <code>QAbstractItemModel</code> to solve the problem easily.</p>
<p dir="auto">like this:</p>
<pre><code>#include &lt;QAbstractItemModel&gt;
#include &lt;QModelIndexList&gt;
[...]
auto    model = ui-&gt;tableWidget-&gt;model();
auto    items = model-&gt;match(
            model-&gt;index(0, 0),
            Qt::DisplayRole,
            QVariant::fromValue(QString("*%1*").arg(Line)),
            1, // -1: for all matching items
            Qt::MatchWildcard);
if (!items.isEmpty()) {
    ui-&gt;tableWidget-&gt;clear();
    ui-&gt;tableWidget-&gt;setItem(0,0,new QTableWidgetItem(Line));
}
[...]
</code></pre>
]]></description><link>https://forum.qt.io/post/421448</link><guid isPermaLink="true">https://forum.qt.io/post/421448</guid><dc:creator><![CDATA[Devopia53]]></dc:creator><pubDate>Wed, 18 Oct 2017 03:05:49 GMT</pubDate></item></channel></rss>