PDA

View Full Version : Not able to increase font size for QTextEdit



shyamsundar1982
27th February 2015, 11:18
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::ScrollBarAlwaysOf f);
label2->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
label2->resize(textWidthInPixels + 30, 30);
label2->setReadOnly(true);
label2->setFocusPolicy(Qt::NoFocus);
label2->setAttribute(Qt::WA_TransparentForMouseEvents, true);
label2->show();

Santosh Reddy
3rd March 2015, 07:38
You forgot to set the font back on to QTextEdit.

...
QFont f1 = label2->font();
QFontMetrics fm(f1);
f1.setPointSize(18);
label2->setFont(f1); //<<<<<<<< Add this
...