Results 1 to 12 of 12

Thread: How to find out the X-Y co-ordinates of the QString characters?

  1. #1
    Join Date
    Jul 2007
    Posts
    25
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Question How to find out the X-Y co-ordinates of the QString characters?

    Hi,

    I've a QLable widget with some text set on it. I want to find out the X and Y co-ordinates of each character of that string, required for setting up my mousePressEvent() function.
    How do I find it out??

    Any help in this regard is highly appreciable.

    Plz


    Thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    May I ask what are you trying to do?
    J-P Nurmi

  3. #3
    Join Date
    Jul 2007
    Posts
    25
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    Hi,

    well I've an application for which I'm going to use the mouse presses or taps on the particular characters of that label string. I've simply set the Text on the label, but now have to take the inputs of mouse presses or taps on that string literals.
    So I thought it would good if I'll get to know the X or Y co-ordinate of that particular character of the string, so that I can compare it with the mouse press event and trigger the right actions accordingly.
    For example, there is a label as "pagenumber / totalpages", so if I press the 'pagenumber' I need to navigate back and if I press the 'totalpages' I need to navigate forward

    I hope you got the scenario now. idk if I'm trying to do something really weird or out the box stuff!

    Thanks
    Last edited by LiCodeX; 10th October 2007 at 09:06.

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    Well, I'd use links. Make sure QLabel::textInteractionFlags contains Qt::LinksAccessibleByMouse (which it does by default). Then just insert HTML to the label and QLabel::linkActivated() gets emitted whenever user activates a link.
    J-P Nurmi

  5. #5
    Join Date
    Jul 2007
    Posts
    25
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    Thanks jpn

    but I guess they have removed that QLabel::textInteractionFlags support from Qt4, b'coz its no more existing over there.
    so will using that flag, affect the application in a way or the other?


    Thanks

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    Quote Originally Posted by LiCodeX View Post
    I guess they have removed that QLabel::textInteractionFlags support from Qt4, b'coz its no more existing over there.
    Well actually, QLabel::textInteractionFlags() was introduced in Qt 4.2. You must be using a pretty old version of Qt since the current version of Qt is already at 4.3.2.
    J-P Nurmi

  7. #7
    Join Date
    Jul 2007
    Posts
    25
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    Quote Originally Posted by jpn View Post
    Well actually, QLabel::textInteractionFlags() was introduced in Qt 4.2. You must be using a pretty old version of Qt since the current version of Qt is already at 4.3.2.
    oh well I'm using the Qt 4.3.2 itself, but the documentation with me was of Qt 4.1, which I forgot to update somehow ,

    Thanks for the help

  8. #8
    Join Date
    Jul 2007
    Posts
    25
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    ok now just an extention to this question:
    considering the example I've given above, if I've couple of links together over there, for 'pagenumber' and 'totalpages', then how do I distinguish between these two? b'coz all I'll get is the linkActivated() signal, but on which basis I've to decide whether to navigate to or fro??

    plz help

    Thanks

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    linkActivated() has a QString parameter that contains the URL of the link clicked. So by changing the href attribute of the link you may add 'labels' to those links.

  10. #10
    Join Date
    Jul 2007
    Posts
    25
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    :? can you plz elaborate it a little more for me?
    it will be really appreciable if you'll provide a short snippet as an example for it.

    Thanks

  11. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    Qt Code:
    1. label->setText("Here's some HTML with <a href='abc'>a couple</a> of <a href='def'>links</a>");
    2. connect(label, SIGNAL(linkActivated(const QString&)), receiver, SLOT(doSomething(const QString&)));
    3.  
    4. void Receiver::doSomething(const QString& link)
    5. {
    6. // do something with 'link' which is either "abc" or "def"
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 10th October 2007 at 14:34. Reason: extended the example a bit
    J-P Nurmi

  12. #12
    Join Date
    Jul 2007
    Posts
    25
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to find out the X-Y co-ordinates of the QString characters?

    Thank you very much jpn and wysota, for generous help in this regard

    Its really appreciable that how helpful can this forum prove for a novice like me

    Thanks again

Similar Threads

  1. QString find Whole word Only
    By bcteh_98 in forum Qt Programming
    Replies: 9
    Last Post: 7th December 2018, 09:47
  2. Problem at time compilation in traslation of language
    By thomasjoy in forum Qt Programming
    Replies: 3
    Last Post: 22nd May 2007, 15:18
  3. Convert from iso-8859-1 to... Something else :-)
    By Nyphel in forum Qt Programming
    Replies: 4
    Last Post: 7th March 2007, 18:59

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.