Results 1 to 3 of 3

Thread: QPlainTextEdit and geometry

  1. #1
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QPlainTextEdit and geometry

    hi,

    i am trying to port over some legacy wxwidgets code to Qt5 and am running into problems. Basically, there is one textbox that contains text elements. Aligned next to the textbox there is an empty widget used for custom drawing. The custom drawings must now be aligned with the elements in the textbox next to it. elements may span an arbitrary amount of linebreaks, but i cant even get it to work with one line. To make things easier, i set a mono-space font.

    The problem is now that i cant get the textlines aligned with my drawing on the widget.


    There seem to be two issues:


    1) at the beginning of the documents, there seems to be some sort of paragraph-break, ie some pixel lines of extra-empty space.

    2) the line height of a text line returned by QFontMetric(font()).height() appears to be off by a little, or there is some linespacing i dont see.


    this picture illustrates the two points:

    https://i.imgur.com/Q1uqK5b.png


    code used for inserting the text line in to the QPlainTextEdit:

    Qt Code:
    1. for(auto vil : items)
    2. {
    3. cur.insertBlock();
    4. cur.insertText("testesttest");
    5. cur.block().setUserData(...);
    6. }
    To copy to clipboard, switch view to plain text mode 


    code used for drawing in the empty widget:

    Qt Code:
    1. for (int i = 0; i < lines; i++)
    2. p->drawLine(width() - 5 - ((i % 2) ? 3 : 0), i*LineHeight(),
    3. width() - 5 - ((i % 2) ? 3 : 0), (i + 1)*LineHeight());
    4.  
    5. int LineHeight()
    6. {
    7. return QFontMetrics(font()).height();
    8. }
    To copy to clipboard, switch view to plain text mode 



    help is appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QPlainTextEdit and geometry

    For line spacing see QFontMetrics::lineSpacing()
    Cheers,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPlainTextEdit and geometry

    lineSpacing() returns the same value as height(). :/


    Added after 8 minutes:


    it looks like the line spacing is hard coded to 1px. if i do height() + 1, it is aligned correctly, provided i scroll down a little.


    That leaves me with the problem of the initial spacing at the very top of the textedit.
    Last edited by tuli; 12th August 2014 at 13:50.

Similar Threads

  1. frameGeometry vs Geometry
    By bossy in forum Newbie
    Replies: 4
    Last Post: 18th October 2013, 00:55
  2. When is the geometry of a QWidget subclass set?
    By Luc4 in forum Qt Programming
    Replies: 3
    Last Post: 3rd May 2011, 21:14
  3. Geometry shader with QT4.7
    By saraksh in forum General Programming
    Replies: 3
    Last Post: 28th March 2011, 16:40
  4. QGraphicsLayout::geometry()
    By isutruk in forum Qt Programming
    Replies: 1
    Last Post: 19th October 2009, 15:43
  5. Painting outside widget geometry?
    By mbjerkne in forum Qt Programming
    Replies: 2
    Last Post: 8th February 2006, 14: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.