Results 1 to 3 of 3

Thread: Custom active fields inside a QGraphicsTextItem

  1. #1
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    2

    Default Custom active fields inside a QGraphicsTextItem

    Hello, I am using some QGraphicsTextItem that need to embed inside of it "special" tags. These tags should be parsed and postprocessed, and the real displayed text should change in response to some action (the idea is the same of Word "fields").
    I am currently using the <a> tag with some special URL in its href attribute, which can be easily parsed and identified, and the text surrounded by <a> and </a> gets updated. I have devised this so far since the user might want to modify, save, and reload the text, and the special field must be kept. Just to finish with an example:
    Qt Code:
    1. <a href="date">***</a>
    To copy to clipboard, switch view to plain text mode 
    after postprocessing becomes
    Qt Code:
    1. <a href="date">2013/02/04</a>
    To copy to clipboard, switch view to plain text mode 
    I am kindly asking you here if there is a less cumbersome method to carry this task out, any idea is welcome, thank you.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Custom active fields inside a QGraphicsTextItem

    I guess you are doing all this with a QGraphicsTextItem derived class item, if not I see that as one nice approach.

    You could use the same way QString does it, just use %1, %2... place holders/tags/fields, and later process them using the QString::arg() functions.

    Raw Text: "Message to %3: %1 %4 very Good Day for %2 for %3"

    %1 = Today
    %2 = Swimming
    %3 = Smith
    %4 = is
    Processed Text: "Message to Smith: Today is very Good Day for Swimming for Smith"

    %1 = Next Sunday
    %2 = Hiking
    %3 = Tom
    %4 = will be
    Processed Text: "Message to Tom: Next Sunday will be very Good Day for Hiking for Tom"
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2013
    Posts
    12
    Thanks
    2

    Default Re: Custom active fields inside a QGraphicsTextItem

    Hello Santosh, thank you for your confirmation on the validity of this method.
    The other method you suggest is fine, but the problem is: what should the end user edit? He/she should not know anything about %1 %2 etc. that are interspersed in the text. He should just see the final/computed result and be aware that that word is "particular". Moreover, I have the particularity that the user edits all this text in WYSIWYG way, with all the formatting of italic, bold, etc.

Similar Threads

  1. how to detect if QGraphicsTextItem is inside viewport
    By mihnen in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2012, 03:57
  2. Replies: 51
    Last Post: 26th November 2010, 13:24
  3. Replies: 0
    Last Post: 30th September 2010, 13:22
  4. QWizard fields and custom properties
    By HelLViS69 in forum Qt Programming
    Replies: 1
    Last Post: 4th May 2010, 16:41
  5. Custom Widget inside a QVboxLayout
    By nemesis in forum Qt Programming
    Replies: 5
    Last Post: 25th June 2008, 14:55

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.