December 10, 2010

orangestar orangestar
Lab Rat
1 posts

[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:

  1. MainWindow::MainWindow(QWidget *parent) :
  2.    QMainWindow(parent),
  3.    ui(new Ui::MainWindow)
  4. {
  5.    ui->setupUi(this);
  6.    setWindowTitle(tr("Text [*]"));
  7.    ui->textEdit->setAlignment(Qt::AlignJustify);
  8.    connect(ui->textEdit->document(), SIGNAL(modificationChanged(bool)),
  9.                this, SLOT(setWindowModified(bool)));
  10. }

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!

3 replies

December 10, 2010

Franzk Franzk
Lab Rat
837 posts

That’s a nasty one…

If this thread or the one at QtCentre [qtcentre.org]()-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.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

December 10, 2010

Wolf P. Wolf P.
Ant Farmer
354 posts
Franzk wrote:
If this thread or the one at QtCentre [qtcentre.org]()-signal-will-not-emit-after-QTextEdit-setAlignment()-called Comes up with a solution, please notify the other forum as well.

Can anyone place an appropriate link to this thread [developer.qt.nokia.com] there? I’ve no account yet. Thx!

December 10, 2010

orangestar orangestar
Lab Rat
1 posts

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.

 
  ‹‹ Qt QTcpSocket different threads for receive & transmit      The height of QListWidget is not consistent with the count of items ››

You must log in to post a reply. Not a member yet? Register here!