Search code examples
c++qtqtextedit

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:

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

not sure how to assign an object here?


Solution

  • The method setBold is not a static method for using it you have to make an object.

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