Troubleshoot with QTextEdit



  • 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?)


  • Qt Champions 2016

    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


  • Moderators

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


  • Qt Champions 2016

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


  • Moderators

    @mrjj said:

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

    also true!



  • 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


  • Qt Champions 2016

    @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 :)



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.