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 to get richtext from textedit?
Forum Updated to NodeBB v4.3 + New Features

How to get richtext from textedit?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 701 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.
  • chaochaoC Offline
    chaochaoC Offline
    chaochao
    wrote on last edited by
    #1
    bool DocHandler::save(const QString &name)
    {
        QString filename=curFile;
    
        if(!name.isEmpty())
            filename=name;
    
        QFile file(filename);
        if(!file.open(QIODevice::WriteOnly))
        {
            const QMessageBox::StandardButton ret
                    = QMessageBox::warning(this, tr("MutiDoc"),
                                           tr("Canot write file %1;\n"
                                              "Erro: %2"
                                              )
                                           .arg(file.fileName()).arg(file.errorString())
                                          );
            return false;
    
        }
        QDataStream out(&file);
        out.setVersion(QDataStream::Qt_5_7);
        QApplication::setOverrideCursor(Qt::WaitCursor);
        out<<this->toPlainText();
        QApplication::restoreOverrideCursor();
    
        setCurrentFile(filename);
        return true;
    }
    

    like this just can get plaintext even if i use QDataStream but QTextStream.I want to get richtext form textedit include color and other info.What can i do? Thank for your help

    jsulmJ 1 Reply Last reply
    0
    • chaochaoC chaochao
      bool DocHandler::save(const QString &name)
      {
          QString filename=curFile;
      
          if(!name.isEmpty())
              filename=name;
      
          QFile file(filename);
          if(!file.open(QIODevice::WriteOnly))
          {
              const QMessageBox::StandardButton ret
                      = QMessageBox::warning(this, tr("MutiDoc"),
                                             tr("Canot write file %1;\n"
                                                "Erro: %2"
                                                )
                                             .arg(file.fileName()).arg(file.errorString())
                                            );
              return false;
      
          }
          QDataStream out(&file);
          out.setVersion(QDataStream::Qt_5_7);
          QApplication::setOverrideCursor(Qt::WaitCursor);
          out<<this->toPlainText();
          QApplication::restoreOverrideCursor();
      
          setCurrentFile(filename);
          return true;
      }
      

      like this just can get plaintext even if i use QDataStream but QTextStream.I want to get richtext form textedit include color and other info.What can i do? Thank for your help

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @chaochao Use http://doc.qt.io/qt-5.7/qtextedit.html#html-prop

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        If the content of the textedit are very simple (no resources) you can save the toHtml() string and reload it using setHtml() if the document is more complex it's currently not available, see https://bugreports.qt.io/browse/QTBUG-9258 , you will have to implement it yourself

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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