Results 1 to 2 of 2

Thread: PlainTextEdit's position indicated by it's viewport's position

  1. #1
    Join Date
    Jul 2015
    Posts
    20
    Thanks
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default PlainTextEdit's position indicated by it's viewport's position

    Qt Code:
    1. QPlainTextEdit* edit = new QPlainTextEdit(this);
    2. QRect* rect = new QRect(100, 400, 200, 80);
    3. edit->setGeometry(*rect);
    4. QPoint test = edit->viewport()->mapToGlobal(edit->viewport()->pos());
    5. qDebug() << test.x() << " " << test.y();
    To copy to clipboard, switch view to plain text mode 

    Simple code; It will display "102 402" instead of "100 400" since it is the viewport's position, not widget position. I need to get the position of the whole widget, not the viewport.
    In my code, I have a pointer to viewport though and need to get the widget's position using this.
    The question is how to get rid of these 2 pixels. Just decreasing test.x and test.y by 2 is not a good idea since I believe this value is not constant for every PlainTextEdit widget.


    Nevermind, made this post too fast. Managed to find out it on my own. Sorries.
    Last edited by Grzyboo; 28th July 2015 at 22:48.

  2. #2
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PlainTextEdit's position indicated by it's viewport's position

    edit->pos() is returning 100,400.
    Thanks :-)

Similar Threads

  1. view position of mouse position in GraphicsScene
    By Raghaw in forum Qt Programming
    Replies: 2
    Last Post: 23rd August 2012, 04:46
  2. Get GPS Position with QML
    By jgaleanog in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 4th August 2011, 11:41
  3. How to change the content's position in viewport?
    By aaron in forum Qt Programming
    Replies: 3
    Last Post: 24th March 2009, 08:37
  4. Replies: 1
    Last Post: 3rd October 2007, 07:34
  5. Replies: 3
    Last Post: 14th April 2006, 11:33

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.