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. Word Wrapping In Plain TextEdit
Qt 6.11 is out! See what's new in the release blog

Word Wrapping In Plain TextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 6.2k 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.
  • B Offline
    B Offline
    brazz
    wrote on last edited by
    #1

    I am trying to display ascii chars on a PlainTextEdit widget, however I've run into the issue where my lines are suddenly cut in half. There is a \n character where I actually want the text to start a new line, so this word wrapping feature is undesirable. I've tried setting the word wrap and line wrap modes to NoWrap, however it still produces the same undesirable image shown below. I can't display all the text for proprietary reasons, but essentially what happens is each C should be the start of a new line. There are 80 chars in each line, hence the loop. The widget is much larger than where the text is wrapped, so I'm really not sure what is happening here. alt text

    uint8_t count = 0;
    QString textualFileCharacterString;
    char currentCharacter;
    const char* currentCharacterPointer = &currentCharacter;
    while (bytePosition < 3200)
    {
        for(count = 0; count < 80; count ++)
        {
            file.seekg(bytePosition);
            file.read((char*)(&ASCIIorEBCDICchar[0]), BUF_LEN_1);
            if (EBCDICtoASCIIConvNeeded == TRUE)
                currentCharacter = ebc_to_ascii_table(ASCIIorEBCDICchar[0]); // file is encoded in EBCDIC
            else
                currentCharacter = ASCIIorEBCDICchar[0]; // file is encoded in ASCII
    
            // if(currentCharacter == 32)//Auto space formatting fix, if current character equals space it converts it to a dot
            //   currentCharacter = 46;
    
            textualFileCharacterString = QString::fromUtf8(currentCharacterPointer, ONE_BYTE); //converts ASCII value to usable QString
            ui->TextualFileHeaderPlainTextEdit->insertPlainText(textualFileCharacterString);
            count++;
            bytePosition++;
        }
        ui->TextualFileHeaderPlainTextEdit->insertPlainText("\n");
    }
    ui->TextualFileHeaderPlainTextEdit->setReadOnly(true);
    ui->TextualFileHeaderPlainTextEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
    ui->TextualFileHeaderPlainTextEdit->setWordWrapMode(QTextOption::NoWrap);
    
    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      @brazz said in Word Wrapping In Plain TextEdit:

      PlainTextEdit

      Hmm. Works as expected for me (Qt 5.9.1, Desktop Linux)

      0_1502025440343_nowrap.png

      void MainWindow::on_pushButton_clicked()
      {
          auto const s = QString("Lorem Ipsum is simply dummy text of the printing and typesetting industry.\nLorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.");
          ui->plainTextEdit->setLineWrapMode(QPlainTextEdit::NoWrap);
          ui->plainTextEdit->setPlainText(s);
      }
      
      1 Reply Last reply
      5
      • B Offline
        B Offline
        brazz
        wrote on last edited by
        #3

        strange, I have a windows 10 partition so os might have an effect. I change the loop to 160 and it works fine now. Odd, but oh well

        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