Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I change the font Size of a QTextEdit in QMainWindow from another class.
QtWS25 Last Chance

How do I change the font Size of a QTextEdit in QMainWindow from another class.

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 929 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Tobias88
    wrote on last edited by
    #1

    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!

    JonBJ 1 Reply Last reply
    0
    • T Tobias88

      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!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Tobias88
      Don't change it from another class. Use a dialog to get a value from the user, have it return the value to the window/text edit which then sets its font size.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tobias88
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved