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. QTextEdit format
Qt 6.11 is out! See what's new in the release blog

QTextEdit format

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 986 Views 1 Watching
  • 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.
  • O Offline
    O Offline
    Oumayma
    wrote on last edited by
    #1

    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);
    }
    
    
    JonBJ 1 Reply Last reply
    0
    • O Oumayma

      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);
      }
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Oumayma
      I thought these would change the font for the whole QTextEdit, 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)?

      O 1 Reply Last reply
      0
      • JonBJ JonB

        @Oumayma
        I thought these would change the font for the whole QTextEdit, 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)?

        O Offline
        O Offline
        Oumayma
        wrote on last edited by
        #3

        @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);
        
        }
        
        JonBJ 1 Reply Last reply
        0
        • O Oumayma

          @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);
          
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Oumayma
          I have tested both your original calls and the new QTextCursor 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.

          O 1 Reply Last reply
          0
          • JonBJ JonB

            @Oumayma
            I have tested both your original calls and the new QTextCursor 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.

            O Offline
            O Offline
            Oumayma
            wrote on last edited by
            #5

            @JonB
            This is the version I have of Qt, my version is superior ¿I should I have yours? :
            d278efaa-fad0-40de-baee-016a3977f675-image.png

            It only works for me if I select the text. With new text it doesn't work for me, which is what I need.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              O 1 Reply Last reply
              0
              • SGaistS SGaist

                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.

                O Offline
                O Offline
                Oumayma
                wrote on last edited by
                #7

                @SGaist
                This is the kit I use to run my application. Is this what you mean?:
                !20fd9553-4b64-4857-8b0d-b3747d73639c-image.png

                1 Reply Last reply
                0

                • Login

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