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?)
-
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 -
@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 isui->QtexteditObj->setAlignment(Qt::AlignRight)
called?
What other calls to the textedit do you have before/after this line? -
Hi
Yeah it should/does,
but crash is also sometimes covered by "doesn't work" ;)
But yes, should have said "silly question, but xx" -
-
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 Rightit's work like should
-
@Matzomatzomatzo said:
Hi
if setAlignment sets the alignment for a paragraph of text
(see doc)When you do
ui->QtexteditObj->setTextI think it replaces the paragraph with a new one since u replace all text
and the default alignment is left for that new paragraphJust guessing. Did not test it :)