I am trying to create a button which underlines the selected text of my QTextEdit
instance.
In the constructor, I am activating the cursor and setting a bool variable for the setFontUnderline method used later.
QTextCursor cursor1 = ui.myQTextfield->textCursor();
ui.myQTextfield->ensureCursorVisible();
test1 = false;
The first method below is executed by pressing the underline button and the second by releasing that.
void Hauptfenster::pressed_underlinebutton()
{
test1 = true;
ui.myQTextfield->setFontUnderline(test1);
}
void Hauptfenster::released_underlinebutton()
{
cursor.clearSelection();
test1 = false;
ui.myQTextfield->setFontUnderline(test1);
}
The problem is that with this code, the selected text first gets underlined by the pressed_underlinebutton() method and then instantly gets de-underlined with the released_underlinebutton method.
With the released_underlinebutton() method, I want to archieve that there is no more selection to de-underline while setting setfontunderline(false) again.