Results 1 to 5 of 5

Thread: QTextEdit and formatting

  1. #1
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QTextEdit and formatting

    Hi.
    I have a QTextEdit. And I have a task to change formatting of the text in text edit.
    First task is to set initial font size. I tried numerous variants:
    1:
    QTextCharFormat cf;
    cf.setFontPointSize(14);
    completedTextEdit->setCurrentCharFormat(cf);

    2:
    completedTextEdit->setStyleSheet ( "font: 14px" );
    3:
    completedTextEdit->setFontPointSize(14);
    4:
    method with setFont (did not work for my surprise)

    All that methods (first 3). But I have problem when using setting font size. If I call zoomIn and zoomOut they do not work. And this functions work well if i don't use setting size.

  2. #2
    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: QTextEdit and formatting

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: QTextEdit and formatting

    I have tried following code:
    QFont f;
    f.setPointSize ( 20 );
    completedTextEdit->document ()->setDefaultFont ( f );

    It does not work...

  4. #4
    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: QTextEdit and formatting

    Maybe the document doesn't use the default font. Please provide a minimal compilable example reproducing the problem.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Aug 2011
    Location
    California, USA
    Posts
    24
    Thanks
    4
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QTextEdit and formatting

    Quote Originally Posted by fusycmr View Post
    I have tried following code:
    QFont f;
    f.setPointSize ( 20 );
    completedTextEdit->document ()->setDefaultFont ( f );

    It does not work...
    Try doing
    Qt Code:
    1. QFont f = completedTextEdit->font(); //Get the current font
    2. f.setPointSize(20);
    3. completedTextEdit->setFont(f);
    To copy to clipboard, switch view to plain text mode 

    If I recall correctly, when I did something like this a few months ago I had to get the current font (and store it temporarily to work on), THEN change its size, THEN set the QTextEdit's font to the modified font.

    Chris

    Edit: Incorrectly capitalized the variable.

Similar Threads

  1. QGroupBox formatting
    By manaila in forum Newbie
    Replies: 2
    Last Post: 16th February 2012, 22:28
  2. Formatting QString
    By thefatladysingsopera in forum Newbie
    Replies: 2
    Last Post: 11th September 2011, 17:16
  3. Number formatting
    By squidge in forum Newbie
    Replies: 4
    Last Post: 29th October 2009, 18:16
  4. Formatting a QString
    By icentenee in forum Newbie
    Replies: 9
    Last Post: 1st October 2006, 17:41
  5. QToolBox Formatting
    By cwalsh in forum Newbie
    Replies: 8
    Last Post: 9th January 2006, 23:08

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.