简体   繁体   English

在Qt中将文本设置为粗体的功能

[英]function to set text as bold in Qt

Hi I am trying to make a function in Qt that sets the font of a QTextEdit to bold: 嗨我想在Qt中创建一个将QTextEdit的字体设置为粗体的函数:

void TextEditor::setBold(){
    if (editor->fontWeight() == 75)
        editor->setFont(QFont::setBold(false));
    else
        editor->setFont(QFont::setBold(true));

}

I am getting error: cannot call member function 'void QFont::setBold(bool)' without object 我收到错误:无法调用成员函数'void QFont :: setBold(bool)'没有对象

not sure how to assign an object here? 不知道如何在这里分配对象?

The method setBold is not a static method for using it you have to make an object. 方法setBold不是使用它的static方法,你必须创建一个对象。

void TextEditor::setBold(){
  QFont font(editor->font());

  if (editor->fontWeight() == 75)
      font.setBold(false);
  else
      font.setBold(true);

   editor->setFont(font);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM