Dmon
Dmon

Reputation: 218

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?

Upvotes: 1

Views: 5910

Answers (1)

masoud
masoud

Reputation: 56479

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);
}

Upvotes: 3

Related Questions