qtextedit change font

断了今生、忘了曾经 提交于 2020-01-03 06:37:10

问题


I am using QTextEdit in my project

I want to change the Font of the text edit area when user clicks on a button. I am using QTextEdit::setCurrentFont() function for this purpose. But, in order to change the font, the user has to first select some text in the textedit area. The font of the whole textedit changes only after selecting some text and then changing the font.

Is there any way to avoid having to select the text to change font? I want the font to change even if the user has not selected any text.

I have also tried this...but, no use..

QTextCharFormat Format = cursor->charFormat()
Format.setFontWeight(QFont::Bold);
cursor->setCharFormat(Format);

Thank you..


回答1:


I solved the problem..actually the problem arisen because I set the cursor to the end of the textedit area for each key event inorder to bring up the scroll bar when the cursor goes out of visibility.. the scroll bar was not automatically appearing because Qt resizes the QTexEdit area. Hence I had to bring up scroll bar this way..

Now, the problem is solved since I made the QTexEdit area as fixed size.. :)



来源:https://stackoverflow.com/questions/12024596/qtextedit-change-font

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!