Unsolved QTextEdit format
-
When adding these functions to my text editor, they don't work unless I have text selected. It is possible to add these text formatting functions from where the cursor is and have them apply to the text that is typed next.
//Metodo triggered de Negrita: void MainWindow::on_actionNegrita_triggered(){ ui->textEdit->setFontWeight(QFont::Bold); } //Metodo triggered de cursiva: void MainWindow::on_actionCursiva_triggered() { ui->textEdit->setFontItalic(true); } //Metodo triggered de subrayado: void MainWindow::on_actionSubrayado_triggered() { ui->textEdit->setFontUnderline(true); }
-
@Oumayma
I thought these would change the font for the wholeQTextEdit
, but I don't know.To change areas, selections or what you type, did you try manipulating the
QTextCursor
and set it via QTextEdit::setTextCursor(const QTextCursor &cursor)? -
@JonB
Hi, I have tried with QTextCursor and QTextcharFormat, and it doesn't work. I pass code tested://Metodo triggered de Negrita: void MainWindow::on_actionNegrita_triggered(){ QTextCursor cursor = ui->textEdit->textCursor(); format.setFontWeight(QFont::Bold); cursor.mergeCharFormat(format); ui->textEdit->setTextCursor(cursor); }
-
@Oumayma
I have tested both your original calls and the newQTextCursor
ones. I find that both do work, contrary to your statements? In both cases:- if any text is selected that text becomes bold/italic/whatever; and then
- regardless of whether text was selected, new text I type in is bold/italic/whatever
Ubuntu 20.04, Qt 5.12.
-
@JonB
This is the version I have of Qt, my version is superior ¿I should I have yours? :
It only works for me if I select the text. With new text it doesn't work for me, which is what I need.
-
Hi,
As noted in the About box: these are the informations about Qt Creator itself. You need to provide the information about the Kit / Qt version you are using to build your application.
-
@SGaist
This is the kit I use to run my application. Is this what you mean?:
!