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. Troubleshoot with QTextEdit
Forum Update on Monday, May 27th 2025

Troubleshoot with QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtexteditaligntroubleshootqt designer
7 Posts 3 Posters 2.3k 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.
  • MatzomatzomatzoM Offline
    MatzomatzomatzoM Offline
    Matzomatzomatzo
    wrote on last edited by Matzomatzomatzo
    #1

    Hello world!

    I got this troubleshoot code in constructer:
    ui->QtexteditObj->setAlignment(Qt::AlignRight)

    This code doesn't work for me if i'm create QTextEdit's object in qt designer,in other ways it's work

    Can anyone tell me the solution?)

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

      Hi and welcome
      Make 100% sure u call it after
      ui->setupUi(this);
      as it constructs what u used in Designer.

      If thats already the case, then i assume
      "in other ways it's work" means that if u do it from a button with text selected, - it works?

      It sets the alignment of the current paragraph, so u might need to select something first
      http://stackoverflow.com/questions/25855024/aligning-text-in-qtextedit

      raven-worxR 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi and welcome
        Make 100% sure u call it after
        ui->setupUi(this);
        as it constructs what u used in Designer.

        If thats already the case, then i assume
        "in other ways it's work" means that if u do it from a button with text selected, - it works?

        It sets the alignment of the current paragraph, so u might need to select something first
        http://stackoverflow.com/questions/25855024/aligning-text-in-qtextedit

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @mrjj said:

        Make 100% sure u call it after
        ui->setupUi(this);
        as it constructs what u used in Designer.

        wouldn't result the otherway around in a crash? ;)

        @Matzomatzomatzo
        when is ui->QtexteditObj->setAlignment(Qt::AlignRight) called?
        What other calls to the textedit do you have before/after this line?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        mrjjM 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @mrjj said:

          Make 100% sure u call it after
          ui->setupUi(this);
          as it constructs what u used in Designer.

          wouldn't result the otherway around in a crash? ;)

          @Matzomatzomatzo
          when is ui->QtexteditObj->setAlignment(Qt::AlignRight) called?
          What other calls to the textedit do you have before/after this line?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi
          Yeah it should/does,
          but crash is also sometimes covered by "doesn't work" ;)
          But yes, should have said "silly question, but xx"

          raven-worxR 1 Reply Last reply
          0
          • mrjjM mrjj

            Hi
            Yeah it should/does,
            but crash is also sometimes covered by "doesn't work" ;)
            But yes, should have said "silly question, but xx"

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            @mrjj said:

            but crash is also sometimes covered by "doesn't work" ;)

            also true!

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            1
            • MatzomatzomatzoM Offline
              MatzomatzomatzoM Offline
              Matzomatzomatzo
              wrote on last edited by
              #6

              i solve this problem, but dont get why it should be like that

              So if i'm add code like this

              ui->QtexteditObj->setAlignment(Qt::AlignRight);
              qDebug() << ui->QtexteditObj->alignment(); // here Align is Right
              ui->QtexteditObj->setText("Type text here"); // but after this code Align is Left
              qDebug() << ui->QtexteditObj->alignment();

              it doesnt work align after setText

              ui->QtexteditObj->setText("Type text here");
              ui->QtexteditObj->setAlignment(Qt::AlignRight);
              qDebug() << ui->QtexteditObj->alignment(); // here Align is Right

              it's work like should

              mrjjM 1 Reply Last reply
              0
              • MatzomatzomatzoM Matzomatzomatzo

                i solve this problem, but dont get why it should be like that

                So if i'm add code like this

                ui->QtexteditObj->setAlignment(Qt::AlignRight);
                qDebug() << ui->QtexteditObj->alignment(); // here Align is Right
                ui->QtexteditObj->setText("Type text here"); // but after this code Align is Left
                qDebug() << ui->QtexteditObj->alignment();

                it doesnt work align after setText

                ui->QtexteditObj->setText("Type text here");
                ui->QtexteditObj->setAlignment(Qt::AlignRight);
                qDebug() << ui->QtexteditObj->alignment(); // here Align is Right

                it's work like should

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #7

                @Matzomatzomatzo said:

                Hi

                if setAlignment sets the alignment for a paragraph of text
                (see doc)

                When you do
                ui->QtexteditObj->setText

                I think it replaces the paragraph with a new one since u replace all text
                and the default alignment is left for that new paragraph

                Just guessing. Did not test it :)

                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