Results 1 to 2 of 2

Thread: Not able to increase font size for QTextEdit

  1. #1
    Join Date
    Feb 2015
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Android

    Default Not able to increase font size for QTextEdit

    Hi all,
    I am trying to increase the font size for the QTextEdit,
    But it is not working.
    Can I know where I am going wrong?

    /* create a lineedit for the text */
    label = new QLineEdit(g_gt_widget);
    g_gt_annotation_label_list << label;
    label->setObjectName(QString("Label%1").arg(numoflabel)) ;
    label->move(startpos);
    label->setText(item->text());
    label->setReadOnly(true);
    label->setFocusPolicy(Qt::NoFocus);
    label->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    label->setStyleSheet("border:0px;font:50px;color:rgb(255 ,255,255);"
    "background-color:rgba(255,255,255,0);");
    label->hide();

    QString s = g_gt_annotation_undo_list.
    at(g_gt_annotation_undo_list.count() - 1);

    label2 = new QTextEdit(g_gt_widget);
    g_gt_annotation_label_list2 << label2;
    label2->move(label->x(), label->y());
    label2->setLineWrapMode(QTextEdit::NoWrap);
    label2->setStyleSheet("border:0px;font-size:50pt;color:rgb(255,255,255);"
    "background-color:rgba(255,255,255,0);");
    QTextCursor cursor = label2->textCursor();
    QTextCharFormat fmt;
    fmt.setFontPointSize(50);
    fmt.setForeground(QBrush(Qt::white));
    fmt.setTextOutline(QPen(QColor(5, 5, 5), 1));
    cursor.insertText(label->text(), fmt);
    QFont f1 = label2->font();
    QFontMetrics fm(f1);
    f1.setPointSize(18);
    s32 textWidthInPixels = fm.width(label2->toPlainText());
    label2->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysO ff);
    label2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff );
    label2->resize(textWidthInPixels + 30, 30);
    label2->setReadOnly(true);
    label2->setFocusPolicy(Qt::NoFocus);
    label2->setAttribute(Qt::WA_TransparentForMouseEvents, true);
    label2->show();

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Not able to increase font size for QTextEdit

    You forgot to set the font back on to QTextEdit.
    Qt Code:
    1. ...
    2. QFont f1 = label2->font();
    3. QFontMetrics fm(f1);
    4. f1.setPointSize(18);
    5. label2->setFont(f1); //<<<<<<<< Add this
    6. ...
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

Similar Threads

  1. Replies: 1
    Last Post: 30th March 2012, 16:46
  2. increase the size of my plot
    By 21did21 in forum Qwt
    Replies: 4
    Last Post: 29th May 2011, 11:03
  3. Increase the distance between two lines in QTextEdit
    By ansar in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2010, 22:08
  4. Font size increase in QtableWidget
    By sosanjay in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2009, 14:51
  5. How to increase font size in arm target
    By soumya in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 2nd September 2009, 05:58

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.