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. QTextEdit::setAlignment not working.
Forum Updated to NodeBB v4.3 + New Features

QTextEdit::setAlignment not working.

Scheduled Pinned Locked Moved General and Desktop
qtextedit align
8 Posts 2 Posters 3.9k Views 2 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
    Pippin
    wrote on last edited by
    #1

    Hello,

    the following code,

    CardLore.setParent(&MainWidget);
    CardLore.setReadOnly(true);
    QString text = "foo foofoofoo foofoo foofoofoofoo foofoo foofoofoofoo foo foofoo foofoofoo foo foofoo";
    CardLore.setText(text);
    CardLore.setAlignment(Qt::AlignJustify);
    CardLore.resize(447, 98);
    CardLore.move(401, 501);
    

    where CardLore is a QTextEdit object, fails to justify the text and I don't know why. What am I missing? I've googled my problem but couldn't find a thread about it that was either recent or working.

    Thanks in advance for any help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Calling setAlignment will make the next paragraph use the alignment. So you have to do:

      CardLore.setAlignment(Qt::AlignJustify);
      CardLore.append(text);
      

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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

        Thanks for your reply!

        Unfortunately this didn't work for me, although it works if I replace Qt::AlignJustify with Qt::AlignRight (I have no idea why), but that's not what I want :(

        1 Reply Last reply
        0
        • P Offline
          P Offline
          Pippin
          wrote on last edited by
          #4

          Status update:

          QPainterObject.drawText(QRect(34, 475, 350, 75), Qt::AlignJustify | Qt::TextWordWrap, someText);

          does wrap the text, but seems unabled to justify it as well. So either I'm using Qt::AlignJustify the wrong way, or Qt::AlignJustify doesn't work on Ubuntu.

          :(

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Are you sure it's not the size of your widget that makes it seems like it's not justified ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            P 1 Reply Last reply
            0
            • SGaistS SGaist

              Are you sure it's not the size of your widget that makes it seems like it's not justified ?

              P Offline
              P Offline
              Pippin
              wrote on last edited by
              #6

              @SGaist

              Well the text was wrapped and each line ended at a different place, so it was clear that the text wasn't justified.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You were using a QTextEdit and now you are using a painter. What is your current code ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Pippin
                  wrote on last edited by
                  #8

                  I apologize, my main concern was about QTextEdit, and I happened to try to do that (as a totally different issue) on a QImage with QPainter. That failed as well, and I mistook this thread for my newer problem.

                  I'm still using the code in the OP.

                  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