[SOLVED] modificationChanged() will not be emitted after QTextEdit::setAlignment() called
-
Hi, there! I wonder if you have found this problem. After I called QTextEdit::setAlignment(Qt::AlignJustify), the textEdit->document()'s modificationChanged(bool) will not be emitted. Here is the key code:
@MainWindow::MainWindow(QWidget parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setWindowTitle(tr("Text []"));
ui->textEdit->setAlignment(Qt::AlignJustify);
connect(ui->textEdit->document(), SIGNAL(modificationChanged(bool)),
this, SLOT(setWindowModified(bool)));
}@If I remove ui->textEdit->setAlignment(Qt::AlignJustify);, everything is OK. But if this line is not removed, the window title will not be changed. I've no idea if this is my fault or something else.
Thank you for your suggestions!
-
That's a nasty one...
If this thread or the one at "QtCentre":http://www.qtcentre.org/threads/36806-modificationChanged()-signal-will-not-emit-after-QTextEdit-setAlignment()-called Comes up with a solution, please notify the other forum as well.
This one is interesting enough to have a look at, but I lack the time at the moment.
-
[quote author="Franzk" date="1291961877"] If this thread or the one at "QtCentre":http://www.qtcentre.org/threads/36806-modificationChanged()-signal-will-not-emit-after-QTextEdit-setAlignment()-called Comes up with a solution, please notify the other forum as well.[/quote]
Can anyone place an appropriate link to "this thread":http://developer.qt.nokia.com/forums/viewthread/2311/ there? I've no account yet. Thx!
-
I have found the problem. The signal modificationChanged(bool) will be emitted when QTextDocument::modified = true. If I called setAlignment() first, this function will set modified, so even I input some text, the signal will not be emitted again, the window title of course will not be changed. If you have to call setAlignment() first, just call QTextDocument::setModified(false); after steAlignment(). This will set modified = false, then everything is OK.