Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3478

QPlainTextEdit::undoAvailable() (and redo) is emitted even if it's read only

XMLWordPrintable

      Signals undoAvailable(bool) and redoAvailable(bool) shouldn't get emitted if the QPlainTextEdit has readOnly to true.

      See Example of this here:

      #include <QWidget>
      #include <QPlainTextEdit>
      #include <QPushButton>
      #include <QVBoxLayout>

      class Widget : public QWidget
      {
      Q_OBJECT
      public:
      Widget();
      public slots:
      void redoAvailableDebug(bool aval);
      void undoAvailableDebug(bool aval);
      void changeText();
      private:
      QPlainTextEdit *textEdit;
      QPushButton *button;
      QVBoxLayout *layout;
      };
      #include <QDebug>
      #include <time.h>
      #include <QTime>

      Widget::Widget()
      {
      textEdit = new QPlainTextEdit();
      button = new QPushButton("Change Text");
      layout = new QVBoxLayout();

      layout->addWidget(textEdit);
      layout->addWidget(button);
      this->setLayout(layout);

      textEdit->setReadOnly(true);

      connect(textEdit, SIGNAL(redoAvailable(bool)), this, SLOT(redoAvailableDebug(bool)));
      connect(textEdit, SIGNAL(undoAvailable(bool)), this, SLOT(undoAvailableDebug(bool)));
      connect(button, SIGNAL(clicked()), this, SLOT(changeText()));

      }

      void Widget::redoAvailableDebug(bool aval)
      {
      qDebug() << "redoSignal Called and " << aval;
      }
      void Widget::undoAvailableDebug(bool aval)
      {
      qDebug() << "undoSignal Called and " << aval;
      }

      void Widget::changeText()
      {
      QTime curr = QTime::currentTime();

      textEdit->insertPlainText(curr.toString());
      textEdit->undo();
      }

      #include <QApplication>

      int main(int argc, char *argv[])
      {
      QApplication a(argc, argv);
      Widget widget;
      widget.show();

      return a.exec();
      }

      #include "main.moc"

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Unassigned Unassigned
            janichol Andy Nichols
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes