Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QTextEdit::setAlignment not working.

    General and Desktop
    qtextedit align
    2
    8
    3203
    Loading More Posts
    • 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
      Pippin last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • P
          Pippin last edited by

          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 Reply Quote 0
          • P
            Pippin last edited by

            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 Reply Quote 0
            • SGaist
              SGaist Lifetime Qt Champion last edited by

              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 Reply Quote 0
              • P
                Pippin @SGaist last edited by

                @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 Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  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 Reply Quote 0
                  • P
                    Pippin last edited by

                    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 Reply Quote 0
                    • First post
                      Last post