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. QPlaintTextEdit and setFont to selected Char

QPlaintTextEdit and setFont to selected Char

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 3.7k 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.
  • P Offline
    P Offline
    Pablik2005
    wrote on last edited by
    #1

    Hi, how can setFont() to selected char in QPlainTextEdit (no to all QPlainTextEdit) ???

    1 Reply Last reply
    0
    • A Offline
      A Offline
      absfrm
      wrote on last edited by
      #2

      are you test it ?
      @
      setCurrentCharFormat()
      @

      If You Want You Can!

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Pablik2005
        wrote on last edited by
        #3

        setCurrentCharFormat () it's work thx ;)
        i have next question, if i want save all text inside QPlainTextEdit to file and load this text(with this font), then i have make big array of QTextCharFormat and save this TextCharFormat for each char in QPlainTextEdit, or is better way ??

        1 Reply Last reply
        0
        • A Offline
          A Offline
          absfrm
          wrote on last edited by
          #4

          you are welcome.
          no,if you save this text with current font,and read it and set it as plain text , it works without any problem with your formats.

          If You Want You Can!

          1 Reply Last reply
          0
          • P Offline
            P Offline
            Pablik2005
            wrote on last edited by
            #5

            But how save with current font ??
            Before i do that:
            Save-
            QTextStream < QPlainTextEdit->toPlainText();
            Load-
            QPlainTextEdit->setPlainText(QTextStream.readAll());

            1 Reply Last reply
            0
            • A Offline
              A Offline
              absfrm
              wrote on last edited by
              #6

              this is works,
              @
              //for save :
              ui->plainTextEdit->toPlainText();
              //this is save the texts with formats.
              @

              If You Want You Can!

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Pablik2005
                wrote on last edited by
                #7

                it's didnt work ;(

                Save
                [code]
                void PageItem::save()
                {

                if( haveFile )
                {
                    if( !isSaved )
                    {
                        if( File->open(QIODevice::WriteOnly | QIODevice::Text ))
                        {
                            QTextStream t_Stream(File);
                            t_Stream <&lt; PlainTextEdit-&gt;toPlainText();
                
                            File->close();
                        }
                
                        isSaved = true;
                
                    }
                }else
                {
                    QFileDialog t_Dialog(0);
                    saveAs(t_Dialog.getSaveFileName(0,"Save"));
                }
                

                }
                [/code]

                Open
                [code]
                if(File->open(QIODevice::ReadOnly | QIODevice::Text))
                {
                QTextStream stream(File);

                    PlainTextEdit->setPlainText(stream.readAll());
                    File->close();
                }
                

                [/code]

                if i save with font after open font is default (not like after save)

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  absfrm
                  wrote on last edited by
                  #8

                  Pablik2005 , I thi* nk you want to save your QPlainTextEdit content with format to rtf file!
                  but,rtf files and it's formats just for Microsoft ;Not Standard For All Platforms!

                  if you want to save your custom text format, you can save it and open it by HTML tags.
                  Convert it to HTML or use QTextEdit as this :
                  @
                  //for open
                  ui->textEdit->setHtml("<b>Bold Text</b>");

                  //for save
                  ui->textEdit->toHtml();
                  @

                  If You Want You Can!

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    absfrm
                    wrote on last edited by
                    #9

                    and if you want to design a text editor , "see this link ":http://qt-apps.org/content/show.php/GoodWord?content=133968

                    If You Want You Can!

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Pablik2005
                      wrote on last edited by
                      #10

                      ok thx for help

                      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