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 Updated to NodeBB v4.3 + New Features

Troubleshoot with QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtexteditaligntroubleshootqt designer
7 Posts 3 Posters 2.4k 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.
  • M Offline
    M Offline
    Matzomatzomatzo
    wrote on 19 Aug 2016, 06:51 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 19 Aug 2016, 07:11 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

      R 1 Reply Last reply 19 Aug 2016, 07:24
      0
      • M mrjj
        19 Aug 2016, 07:11

        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

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 19 Aug 2016, 07:24 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

        M 1 Reply Last reply 19 Aug 2016, 07:29
        0
        • R raven-worx
          19 Aug 2016, 07:24

          @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?

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 19 Aug 2016, 07:29 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"

          R 1 Reply Last reply 19 Aug 2016, 07:30
          0
          • M mrjj
            19 Aug 2016, 07:29

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

            R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 19 Aug 2016, 07:30 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
            • M Offline
              M Offline
              Matzomatzomatzo
              wrote on 19 Aug 2016, 08:12 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

              M 1 Reply Last reply 19 Aug 2016, 08:26
              0
              • M Matzomatzomatzo
                19 Aug 2016, 08:12

                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

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 19 Aug 2016, 08:26 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

                7/7

                19 Aug 2016, 08:26

                • Login

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