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

QPlainTextEdit

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 301 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.
  • D Offline
    D Offline
    dan1973
    wrote on last edited by
    #1

    Hi,
    set undo not working in QPlainTextEdit below

        pte1 = new QPlainTextEdit("hello\r\nDan\nhow r\nyou\nhi\nAnd\nhello\nagain \ndkd\naee\nwa\ndaf"
            "\nAnd his this is a long long long text which has to cross the widget width andersonkddkdkdk show line wrap mode function to test", this);
        pte1->setGeometry(10, 10, 400, 100);
        pte1->setBackgroundVisible(true);
        pte1->setCenterOnScroll(true);
        pte1->setCursorWidth(3);
        pte1->setDocumentTitle("Dan Document");
        pte1->setLineWrapMode(QPlainTextEdit::NoWrap);
        pte1->setMaximumBlockCount(10);
        pte1->setOverwriteMode(false);
        pte1->setPlaceholderText("Shows Status here");
        pte1->setUndoRedoEnabled(true);
    

    Any help is very useful.

    Thanks.
    Dan

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dan1973
      wrote on last edited by
      #3

      It works with this code below!!

      <
      pte1 = new QPlainTextEdit("hello\r\nsdan\nhow r\nyou\nhi\nthis was him dan\r\n And\nhello\nagain \ndkd\naee\nwa\ndaf"
      "\nAnd his this is a long long long text which has to cross the widget width andersonkddkdkdk show line wrap mode function to test", this);
      pte1->setGeometry(10, 10, 400, 100);
      pte1->setBackgroundVisible(true);
      pte1->setCenterOnScroll(true);
      pte1->setCursorWidth(3);
      pte1->setDocumentTitle("Dan Document");
      // pte1->setLineWrapMode(QPlainTextEdit::NoWrap);
      // pte1->setMaximumBlockCount(10);
      pte1->setOverwriteMode(false);
      pte1->setPlaceholderText("Shows Status here");
      pte1->setWordWrapMode(QTextOption::WordWrap);
      connect(pte1, SIGNAL(cursorPositionChanged()), this, SLOT(cpc1()));

      pt1.setX(10);
      pt1.setY(4);
      
      QTextDocument *td1;
      td1 = pte1->document();
      

      // pte1->setUndoRedoEnabled(true);
      // pte1->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::TextSelectableByKeyboard);
      // pte1->setTabStopDistance(200);
      // pte1->setTabChangesFocus(true);
      // pte1->setPlainText("Hei Dan");
      // pte1->setDocumentTitle("Hi dan doc");
      // pte1->setReadOnly(true);

      qDebug() << "block count: " << pte1->blockCount();
      qDebug() << "Doc Title: " << pte1->documentTitle();
      qDebug() << "Plain Text: " << pte1->toPlainText();
      qDebug() << "Anchor at 20: " << pte1->anchorAt(QPoint(0, 0));
      qDebug() << "Can Paste? " << pte1->canPaste();
      qDebug() << "CurCharFmt: " << pte1->currentCharFormat();
      qDebug() << "Cur Rect: " << pte1->cursorRect().x() << " " << pte1->cursorRect().y();
      qDebug() << "doc: " << td1->toPlainText();
      qDebug() << "isUndoRedoEn? " << pte1->isUndoRedoEnabled();
      
      1 Reply Last reply
      0
      • D Offline
        D Offline
        dan1973
        wrote on last edited by
        #2

        In above code Ctrl + Z (undo operation) is not working

        1 Reply Last reply
        0
        • D Offline
          D Offline
          dan1973
          wrote on last edited by
          #3

          It works with this code below!!

          <
          pte1 = new QPlainTextEdit("hello\r\nsdan\nhow r\nyou\nhi\nthis was him dan\r\n And\nhello\nagain \ndkd\naee\nwa\ndaf"
          "\nAnd his this is a long long long text which has to cross the widget width andersonkddkdkdk show line wrap mode function to test", this);
          pte1->setGeometry(10, 10, 400, 100);
          pte1->setBackgroundVisible(true);
          pte1->setCenterOnScroll(true);
          pte1->setCursorWidth(3);
          pte1->setDocumentTitle("Dan Document");
          // pte1->setLineWrapMode(QPlainTextEdit::NoWrap);
          // pte1->setMaximumBlockCount(10);
          pte1->setOverwriteMode(false);
          pte1->setPlaceholderText("Shows Status here");
          pte1->setWordWrapMode(QTextOption::WordWrap);
          connect(pte1, SIGNAL(cursorPositionChanged()), this, SLOT(cpc1()));

          pt1.setX(10);
          pt1.setY(4);
          
          QTextDocument *td1;
          td1 = pte1->document();
          

          // pte1->setUndoRedoEnabled(true);
          // pte1->setTextInteractionFlags(Qt::LinksAccessibleByKeyboard | Qt::TextSelectableByKeyboard);
          // pte1->setTabStopDistance(200);
          // pte1->setTabChangesFocus(true);
          // pte1->setPlainText("Hei Dan");
          // pte1->setDocumentTitle("Hi dan doc");
          // pte1->setReadOnly(true);

          qDebug() << "block count: " << pte1->blockCount();
          qDebug() << "Doc Title: " << pte1->documentTitle();
          qDebug() << "Plain Text: " << pte1->toPlainText();
          qDebug() << "Anchor at 20: " << pte1->anchorAt(QPoint(0, 0));
          qDebug() << "Can Paste? " << pte1->canPaste();
          qDebug() << "CurCharFmt: " << pte1->currentCharFormat();
          qDebug() << "Cur Rect: " << pte1->cursorRect().x() << " " << pte1->cursorRect().y();
          qDebug() << "doc: " << td1->toPlainText();
          qDebug() << "isUndoRedoEn? " << pte1->isUndoRedoEnabled();
          
          1 Reply Last reply
          0
          • D dan1973 has marked this topic as solved on

          • Login

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