Results 1 to 9 of 9

Thread: resize QTextEdit

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resize QTextEdit

    You're right, I messed up with textArea->size() and textArea->viewport()->size()...
    The six points is the difference in size between the textArea and the viewport of it, I guess.

    In the meantime I fixed the other problems as well:

    I centred the QTextArea in the centre of the QScrollArea by:
    Qt Code:
    1. scrollArea->setAlignment(Qt::AlignCenter);
    To copy to clipboard, switch view to plain text mode 
    removing:
    Qt Code:
    1. scrollArea->setAutoFillBackground(true);
    To copy to clipboard, switch view to plain text mode 
    fixed the problem with the background of the scrollbar.

    Now I'm wondering how I can scale the contents of the QTextEdit. I tried using zoomIn and zoomOut but I can't get the scaling the same proportions as the scaling of the QTextEdit. Is it possible to scale text from a QTextEdit to a certain percentage?

  2. #2
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resize QTextEdit

    i haven't used it yet, but i think you should use void QFont::setStretch ( int factor )

  3. #3
    Join Date
    Apr 2007
    Posts
    76
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

  4. The following user says thank you to codebehind for this useful post:

    maartenS (21st September 2008)

  5. #4
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resize QTextEdit

    Quote Originally Posted by codebehind View Post
    Thanks! I'll try that one!

  6. #5
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    4
    Thanked 5 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: resize QTextEdit

    Trying
    Qt Code:
    1. QFont currentFont = textArea->font();
    2. currentFont.setStretch(125)
    To copy to clipboard, switch view to plain text mode 
    doesn't have any effect.
    I tried this:
    Qt Code:
    1. qreal currentFontPointSize = textArea->font().pointSize();
    2. qreal newFontPointSize = currentFontPointSize * 0.8;
    3. qreal fontPointSizeChange = currentFontPointSize - newFontPointSize;
    4. textArea->zoomOut(fontPointSizeChange);
    To copy to clipboard, switch view to plain text mode 
    for zooming out and
    Qt Code:
    1. qreal currentFontPointSize = textArea->font().pointSize();
    2. qreal newFontPointSize = currentFontPointSize * 1.25;
    3. qreal fontPointSizeChange = newFontPointSize - currentFontPointSize;
    4. textArea->zoomIn(fontPointSizeChange);
    To copy to clipboard, switch view to plain text mode 
    for zooming in and that works!

    Only problem I now have is that the fonts of the QtextDocument are also changing and I want to keep that the same, because I'm making a pdf of the QTextDocument.
    When I zoomOut the QTextEdit I get very small fonts in the pdf and I want to keep the same proportions. That's why I thought of changing the size of the QTextDocument as well.
    I tried:
    Qt Code:
    1. QSizeF currentDocumentSize = textArea->document()->size();
    2. textArea->document()->setPageSize(0.8 * currentDocumentSize);
    To copy to clipboard, switch view to plain text mode 
    and
    Qt Code:
    1. textArea->document()->setPageSize(textArea->size());
    To copy to clipboard, switch view to plain text mode 
    both don't give the good size, they make the QTextEdit a tiny bit to large.

    Do you have any idea how I can resize the QTextEdit while keeping the QTextDocument the same size for pdf and printing?
    Or am I trying to do things with a QTextWidget that are not possible and should I use an own Widget?

Similar Threads

  1. QTextEdit super slow resize
    By bunjee in forum Qt Programming
    Replies: 5
    Last Post: 13th May 2008, 17:09
  2. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  3. QTextEdit auto resize
    By bunjee in forum Qt Programming
    Replies: 4
    Last Post: 26th October 2007, 19:59
  4. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  5. postponing resize event
    By Honestmath in forum Qt Programming
    Replies: 11
    Last Post: 26th February 2006, 00:32

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
  •  
Qt is a trademark of The Qt Company.