How do I change the font Size of a QTextEdit in QMainWindow from another class.
-
Hello, I've been searching days for answers now and I am just too stupid to understand this. I have got the QMainWindow with the QTextEditor and I have got the QDialog where I want to change it by 1 on a button press. I already came up with this to change the font size atleast in the QMainWindow class:
QTextCursor cursor = ui.editor->textCursor(); cursor.select(QTextCursor::Document); ui.editor->setTextCursor(cursor); ui.editor->setFontPointSize(size); cursor.clearSelection(); ui.editor->setTextCursor(cursor);
but I need to change it in the QDialog class. How do I do this? I mean, it can't be impossible, right?
Thank you very much for reading!
-
I got the answer with the help of @JonB.
I made a getter and a setter for the int that is the size.
I made an temporary int in the other class, then called the getter and set this to the value of the temporary integer:mainWindow mW; tempInt = mW.getValue();
then I made it bigger by one and used the setter to set the original value of the mainWindow class:
tempInt++; mW.setValue(tempInt);
In the header of the mainWinow class, I declared the QDialog class:
dialogClass *dC;
In the mainWindow class itself, I used the exec(); method to check if the QDialog is closed and then set font size of the QTextEditor:
dC = new dialogClass(this); if(dC.exec() = 0){ /*0 = rejected (what we need to see if it is closed), 1 = accepted (didn't click the X button, but clicked any other button like 'OK' or sth)*/ QTextCursor cursor = ui.textEditor->textCursor(); cursor.select(QTextCursor::Document); ui.textEditor->setTextCursor(cursor); ui.textEditor->setFontPointSize(size); cursor.clearSelection(); ui.textEditor->setTextCursor(cursor); }
This is the solution for me.