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. Help Changing Format of TextEdit Without Replacing Contents
Forum Updated to NodeBB v4.3 + New Features

Help Changing Format of TextEdit Without Replacing Contents

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 121 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.
  • C Offline
    C Offline
    CodermanBill
    wrote on last edited by
    #1

    For some reason, I can't use "toPlainText()" and "toHtml()" as the arguments for "setPlainText()" and "setHtml()."

    I'm able to get toPlainText() and toHtml() in the console just fine, but it just doesn't convert.

    void TextFinder::on_checkBox_clicked()
    {
        qDebug() << "on_checkBox_clicked() called";
        // Check if the checkbox is checked
        if (ui_checkBox->isChecked())
        {
            // Set the textEdit to plain text
            ui_textEdit->setPlainText(ui_textEdit->toPlainText());
        }
        else
        {
            // Set the textEdit to HTML format
            ui_textEdit->setHtml(ui_textEdit->toHtml());
        }
    }
    

    I even tried this:

    void TextFinder::on_checkBox_clicked()
    {
        qDebug() << "on_checkBox_clicked() called";
    
        // Retrieve the current content of the textEdit
        QString currentText = ui_textEdit->toPlainText();
    
        if (ui_checkBox->isChecked())
        {
            // Convert plain text to HTML by wrapping it with basic HTML tags
            QString htmlText = "<html><body><p>" + currentText.toHtmlEscaped().replace("\n", "<br>") + "</p></body></html>";
            ui_textEdit->setHtml(htmlText);
        }
        else
        {
            // Set the textEdit back to plain text
            ui_textEdit->setPlainText(currentText);
        }
    }
    

    but nothing changed.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @CodermanBill wrote, "but nothing changed".

      You take some plain text, wrap it in HTML that does not attempt to style or otherwise format it, reinsert it into the editor, and expect something to change (I assume visually). What exactly are you expecting?

      1 Reply Last reply
      3

      • Login

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