[Interest] How to get word that was clicked on in a table view or table widget?

Alexei Vinidiktov alexei.vinidiktov at gmail.com
Sat Oct 12 09:27:27 CEST 2013


Thanks for your tips, Tony. I'm going to try them.

The model will be storing QStrings but I still need to figure out which
class to use: a table widget or a table view, or maybe even a list widget
(view).


On Sat, Oct 12, 2013 at 12:48 PM, Tony Rietwyk <tony at rightsoft.com.au>wrote:

> Hi Alexei, ****
>
> ** **
>
> Interesting question.  How does your model get the display text?  I assume
> your model (or the QTableWidget model) is storing a QString.  In the cell
> click handler you can theoretically: ****
>
> ** **
>
> - push the display text into a QTextEdit (hidden for release builds)****
>
> - format it with the same font, margins, etc, as the cell****
>
> - set the max width to the cell width****
>
> - use cursorForPosition to get a QTextCursor for the mouse offset within
> in the cell****
>
> - select the current word using select(QTextCursor::WordUnderCursor)****
>
> - use selectedText to get the word. ****
>
> ** **
>
> The hard part is mimicking the formatting of the cell, and forcing the
> text edit to do its layout changes. ****
>
> ** **
>
> Hope that helps, ****
>
> ** **
>
> Tony.****
>
> ** **
>
> ** **
>
> *From:* interest-bounces+tony=rightsoft.com.au at qt-project.org [mailto:
> interest-bounces+tony=rightsoft.com.au at qt-project.org] *On Behalf Of *Alexei
> Vinidiktov
> *Sent:* Saturday, 12 October 2013 3:44 PM
> *To:* interest at qt-project.org
> *Subject:* Re: [Interest] How to get word that was clicked on in a table
> view or table widget?****
>
> ** **
>
> I forgot to mention that the table view or table widget is not editable.**
> **
>
> ** **
>
> On Sat, Oct 12, 2013 at 11:21 AM, Alexei Vinidiktov <
> alexei.vinidiktov at gmail.com> wrote:****
>
> Hello,****
>
> ** **
>
> I need to get the word that was clicked on in a table widget or table view
> cell.****
>
> ** **
>
> Is it possible? If so, how would I do that?****
>
> ** **
>
> Thanks.
> ****
>
> ** **
>
> --
> Alexei Vinidiktov ****
>
>
>
> ****
>
> ** **
>
> --
> Alexei Vinidiktov ****
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>


-- 
Alexei Vinidiktov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20131012/42627c2f/attachment.html>


More information about the Interest mailing list