<div dir="ltr"><div><div>Really thanks to Maurizio<br></div>I will try this.I agree with you and was thinking if someone had a solution with re library and regix could be better for me .<br></div> <br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 20, 2018 at 6:09 PM, Maurizio Berti <span dir="ltr"><<a href="mailto:maurizio.berti@gmail.com" target="_blank">maurizio.berti@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I know you already found a solution, but I decided to give it a try anyway, just out of curiosity.<br>I didn't like the idea of using another QWidget, which might involve QStyle issues, then I found out that it's possible to use QTextDocument.<div>This is a simple implementation that just matches the text in all items (no actual search in the model).</div><div><br></div><div><br></div><div><div><font face="monospace, monospace">class MatchDelegate(QtWidgets.<wbr>QStyledItemDelegate):</font></div><div><font face="monospace, monospace"> regex = re.compile('')</font></div><div><font face="monospace, monospace"><div> fakeIndex = QtCore.QModelIndex()</div><div><br></div></font></div><div><font face="monospace, monospace"> def paint(self, qp, option, index):</font></div><div><font face="monospace, monospace"> self.initStyleOption(option, index)</font></div><div><font face="monospace, monospace"> td = QtGui.QTextDocument()</font></div><div><font face="monospace, monospace"> if self.regex.pattern:</font></div><div><font face="monospace, monospace"> splitted = self.regex.split(option.text)</font></div><div><font face="monospace, monospace"> matches = iter(self.regex.findall(<wbr>option.text))</font></div><div><font face="monospace, monospace"> text = ''</font></div><div><font face="monospace, monospace"> for words in splitted[:-1]:</font></div><div><font face="monospace, monospace"> text += words + '<b>{}</b>'.format(matches.<wbr>next())</font></div><div><font face="monospace, monospace"> text += splitted[-1]</font></div><div><font face="monospace, monospace"> else:</font></div><div><font face="monospace, monospace"> text = option.text</font></div><div><font face="monospace, monospace"> td.setHtml(text)</font></div><div><font face="monospace, monospace"> option.text = ''</font></div><div><font face="monospace, monospace"> # Using an invalid index avoids painting of the text</font></div><div><font face="monospace, monospace"> QtWidgets.QStyledItemDelegate.<wbr>paint(self, qp, option, self.fakeIndex)</font></div><div><font face="monospace, monospace"> qp.save()</font></div><div><font face="monospace, monospace"> qp.translate(option.rect.<wbr>topLeft())</font></div><div><font face="monospace, monospace"> td.drawContents(qp, QtCore.QRectF(0, 0, option.rect.width(), option.rect.height()))</font></div><div><font face="monospace, monospace"> qp.restore()</font></div><div><br></div><div><span style="font-family:monospace,monospace;line-height:1.5"><br></span></div><div><span style="font-family:monospace,monospace;line-height:1.5">class Widget(QtWidgets.QWidget):</span><br></div></div><div><font face="monospace, monospace"> def __init__(self):</font></div><div><font face="monospace, monospace"> [...]</font></div><div><div style="font-family:monospace,monospace"> self.delegate = MatchDelegate()</div><div style="font-family:monospace,monospace"> self.table.setItemDelegate(<wbr>self.delegate)</div><div style="font-family:monospace,monospace"></div><div><font face="monospace, monospace"> self.search = QtWidgets.QLineEdit()</font></div><div><span style="font-family:monospace,monospace;line-height:1.5"> self.search.textChanged.<wbr>connect(self.findText)</span><br></div></div><div><font face="monospace, monospace"><div><div style="font-family:Arial,Helvetica,sans-serif"><font face="monospace, monospace"> [...]</font></div><div style="font-family:Arial,Helvetica,sans-serif"></div></div><div><div><br></div><div> def findText(self, text):</div><div><span style="line-height:1.5"> self.delegate.regex = re.compile(text, re.I)</span><br></div><div> self.table.viewport().update()</div></div></font></div><div><br></div><div><br></div><div>Of course it doesn't take the text size change into account whenever bold characters are in place, so the sizeHint is not perfect. Also, it might be possible to implement QFontMetrics' elidedText, again with some small issues about font size changes.<br></div><div><br></div><div>Maurizio</div><div><br></div></div><div><div class="h5"><br><div class="gmail_quote"><div dir="ltr">Il giorno lun 20 ago 2018 alle ore 11:31 Maziar Parsijani <<a href="mailto:maziar.parsijani@gmail.com" target="_blank">maziar.parsijani@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><h3 class="m_7375396995481516372m_5740204084834526960gmail-iw"><span name="Denis Rouzaud" class="m_7375396995481516372m_5740204084834526960gmail-gD">Hi Denis Rouzaud</span></h3><p>This question was for 19days ago.But you are correct the best method is html delegate and I did it but I couldn't fix that with my table and the table was changed but it worked nice.<br></p></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 20, 2018 at 12:28 PM, Denis Rouzaud <span dir="ltr"><<a href="mailto:denis.rouzaud@gmail.com" target="_blank">denis.rouzaud@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">This is not easily done.<div>You'd have to create a custom delegate using a QLabbel and use html in there.</div><div><br></div><div>I have been creating a search tool for tables and ending up highlighting the whole cell. </div><div>The effort and the risk of bad results is just not worth the effort IMHO.</div><div><br></div><div>Denis</div></div><br><div class="gmail_quote"><div><div class="m_7375396995481516372m_5740204084834526960h5"><div dir="ltr">Le mar. 31 juil. 2018 à 23:05, Maziar Parsijani <<a href="mailto:maziar.parsijani@gmail.com" target="_blank">maziar.parsijani@gmail.com</a>> a écrit :<br></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_7375396995481516372m_5740204084834526960h5"><div dir="ltr"><div class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-post-text">
<p>I use method1 to find some text in qtablewidget rows.</p><p>
method1 :</p>
<pre class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-lang-py m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-prettyprint m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-prettyprinted"><code><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-kwd">def</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-typ">FindItem</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">(</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">self</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">):</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
items </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">=</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> self</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-typ">SuraBRS</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">findItems</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">(</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
self</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-typ">SearchTbox</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">text</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">(),</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-typ">QtCore</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-typ">Qt</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-typ">MatchContains</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">)</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-kwd">if</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> items</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">:</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
results </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">=</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-str">'\n'</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">join</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">(</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-str">'row %d column %d'</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">%</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">(</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">item</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">row</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">()</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">+</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-lit">1</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">,</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> item</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">.</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">column</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">()</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">+</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-lit">1</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">)</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-kwd">for</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> item </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-kwd">in</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> items</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">)</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-kwd">else</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">:</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
results </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">=</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln"> </span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-str">'Found Nothing'</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">
</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-kwd">print</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">(</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pln">results</span><span class="m_7375396995481516372m_5740204084834526960m_5955850977701824064m_1845155414697011962gmail-pun">)</span></code></pre>
<p>Now I want to know how to highlight results or change their color.<strong>I want to select and highlight that text or character not all of the row or column</strong>.</p>
</div></div></div></div>
______________________________<wbr>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>mailman/listinfo/pyqt</a></blockquote></div><span class="m_7375396995481516372m_5740204084834526960HOEnZb"><font color="#888888">-- <br><div dir="ltr" class="m_7375396995481516372m_5740204084834526960m_5955850977701824064gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">
<p class="m_7375396995481516372m_5740204084834526960m_5955850977701824064inbox-inbox-inbox-inbox-p1"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:10pt">Denis Rouzaud</span><br style="color:rgb(0,0,0);font-family:Times;font-size:medium"><a href="mailto:denis@opengis.ch" style="font-family:Times;font-size:medium" target="_blank"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:8pt">denis@opengis.ch</span> </a><br style="color:rgb(0,0,0);font-family:Times;font-size:medium"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:8pt"><a>+41 76 370 21 22</a></span></p><p class="m_7375396995481516372m_5740204084834526960m_5955850977701824064inbox-inbox-inbox-inbox-p1"><span style="color:rgb(0,0,0);font-family:Verdana,sans-serif;font-size:8pt"><a><br></a></span></p></div></div>
</font></span></blockquote></div><br></div>
______________________________<wbr>_________________<br>
PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
<a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.<wbr>riverbankcomputing.com/<wbr>mailman/listinfo/pyqt</a></blockquote></div><br clear="all"><div><br></div>-- <br></div></div><div dir="ltr" class="m_7375396995481516372gmail_signature" data-smartmail="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>
</blockquote></div><br></div>