QTextEdit设置行高
方法:
获得QTextEdit的QTextCursor(光标),给光标设置一个指定行高的段落格式,再讲该光标设置给QTextEdit。
//获得eidt光标
QTextCursor cursor = edit->textCursor();
//为光标指定一个行高为20的段落格式
QTextBlockFormat block_format;
block_format.setLineHeight(20, QTextBlockFormat::FixedHeight);
cursor.setBlockFormat(block_format);
//把光标再设置给edit
edit->setTextCursor(textCursor);
QTextEdit设置背景色
一般通过如下样式表给QTextEdit设置背景色。
edit->setStyleSheet("QTextEdit{background-color:rgba(0,0,0,0);}");
但是经常遇到背景色设置不生效的问题。
这个问题一般是eidt的父对象或祖先对象设置了背景透明属性导致的:
widget->setAttribut(Qt::WA_TranslucentBackground);
解决方案:
在样式表中设置任一和border有关的属性。
edit->setStyleSheet("QTextEdit{background-color:rgba(0,0,0,0); border:0px;}");