Add ReadOnlyChange event to widgets that support setReadOnly(bool).
This is useful for widget styles to react when widgets are set read-only, e.g. to update their palette accordingly. [ChangeLog][QtWidgets] All widgets with a setReadOnly method now send a ReadOnlyChange event (e.g. for app-specific palette changes) Change-Id: I74719a3e1b7d034d9bfc94305f846f42aae935bd Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
This commit is contained in:
parent
27016b89ae
commit
73d761ffe5
@ -192,6 +192,7 @@ QT_BEGIN_NAMESPACE
|
|||||||
\value Polish The widget is polished.
|
\value Polish The widget is polished.
|
||||||
\value PolishRequest The widget should be polished.
|
\value PolishRequest The widget should be polished.
|
||||||
\value QueryWhatsThis The widget should accept the event if it has "What's This?" help.
|
\value QueryWhatsThis The widget should accept the event if it has "What's This?" help.
|
||||||
|
\value ReadOnlyChange Widget's read-only state has changed (since Qt 5.4).
|
||||||
\value RequestSoftwareInputPanel A widget wants to open a software input panel (SIP).
|
\value RequestSoftwareInputPanel A widget wants to open a software input panel (SIP).
|
||||||
\value Resize Widget's size changed (QResizeEvent).
|
\value Resize Widget's size changed (QResizeEvent).
|
||||||
\value ScrollPrepare The object needs to fill in its geometry information (QScrollPrepareEvent).
|
\value ScrollPrepare The object needs to fill in its geometry information (QScrollPrepareEvent).
|
||||||
|
@ -150,6 +150,8 @@ public:
|
|||||||
WindowUnblocked = 104, // windows modal blocking has ended
|
WindowUnblocked = 104, // windows modal blocking has ended
|
||||||
WindowStateChange = 105,
|
WindowStateChange = 105,
|
||||||
|
|
||||||
|
ReadOnlyChange = 106, // readonly state has changed
|
||||||
|
|
||||||
ToolTip = 110,
|
ToolTip = 110,
|
||||||
WhatsThis = 111,
|
WhatsThis = 111,
|
||||||
StatusTip = 112,
|
StatusTip = 112,
|
||||||
|
@ -8224,6 +8224,7 @@ bool QWidget::event(QEvent *event)
|
|||||||
case QEvent::MacSizeChange:
|
case QEvent::MacSizeChange:
|
||||||
case QEvent::ContentsRectChange:
|
case QEvent::ContentsRectChange:
|
||||||
case QEvent::ThemeChange:
|
case QEvent::ThemeChange:
|
||||||
|
case QEvent::ReadOnlyChange:
|
||||||
changeEvent(event);
|
changeEvent(event);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -8395,7 +8396,7 @@ bool QWidget::event(QEvent *event)
|
|||||||
QEvent::ModifiedChange, QEvent::MouseTrackingChange,
|
QEvent::ModifiedChange, QEvent::MouseTrackingChange,
|
||||||
QEvent::ParentChange, QEvent::WindowStateChange,
|
QEvent::ParentChange, QEvent::WindowStateChange,
|
||||||
QEvent::LanguageChange, QEvent::LocaleChange,
|
QEvent::LanguageChange, QEvent::LocaleChange,
|
||||||
QEvent::LayoutDirectionChange.
|
QEvent::LayoutDirectionChange, QEvent::ReadOnlyChange.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
void QWidget::changeEvent(QEvent * event)
|
void QWidget::changeEvent(QEvent * event)
|
||||||
|
@ -315,6 +315,8 @@ void QAbstractSpinBox::setReadOnly(bool enable)
|
|||||||
Q_D(QAbstractSpinBox);
|
Q_D(QAbstractSpinBox);
|
||||||
d->readOnly = enable;
|
d->readOnly = enable;
|
||||||
d->edit->setReadOnly(enable);
|
d->edit->setReadOnly(enable);
|
||||||
|
QEvent event(QEvent::ReadOnlyChange);
|
||||||
|
QApplication::sendEvent(this, &event);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1348,6 +1348,8 @@ void QLineEdit::setReadOnly(bool enable)
|
|||||||
#ifndef QT_NO_CURSOR
|
#ifndef QT_NO_CURSOR
|
||||||
setCursor(enable ? Qt::ArrowCursor : Qt::IBeamCursor);
|
setCursor(enable ? Qt::ArrowCursor : Qt::IBeamCursor);
|
||||||
#endif
|
#endif
|
||||||
|
QEvent event(QEvent::ReadOnlyChange);
|
||||||
|
QCoreApplication::sendEvent(this, &event);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2529,6 +2529,8 @@ void QPlainTextEdit::setReadOnly(bool ro)
|
|||||||
}
|
}
|
||||||
setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));
|
setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));
|
||||||
d->control->setTextInteractionFlags(flags);
|
d->control->setTextInteractionFlags(flags);
|
||||||
|
QEvent event(QEvent::ReadOnlyChange);
|
||||||
|
QApplication::sendEvent(this, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -2122,6 +2122,8 @@ void QTextEdit::setReadOnly(bool ro)
|
|||||||
}
|
}
|
||||||
d->control->setTextInteractionFlags(flags);
|
d->control->setTextInteractionFlags(flags);
|
||||||
setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));
|
setAttribute(Qt::WA_InputMethodEnabled, shouldEnableInputMethod(this));
|
||||||
|
QEvent event(QEvent::ReadOnlyChange);
|
||||||
|
QApplication::sendEvent(this, &event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -393,18 +393,31 @@ void tst_QSpinBox::valueChangedHelper(int value)
|
|||||||
actualValues << value;
|
actualValues << value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MySpinBox: public QSpinBox
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MySpinBox(QWidget *parent = 0) : QSpinBox(parent) {}
|
||||||
|
|
||||||
|
void changeEvent(QEvent *ev) {
|
||||||
|
eventsReceived.append(ev->type());
|
||||||
|
}
|
||||||
|
QList<QEvent::Type> eventsReceived;
|
||||||
|
};
|
||||||
|
|
||||||
void tst_QSpinBox::setReadOnly()
|
void tst_QSpinBox::setReadOnly()
|
||||||
{
|
{
|
||||||
QSpinBox spin(0);
|
MySpinBox spin(0);
|
||||||
spin.show();
|
spin.show();
|
||||||
QTest::keyClick(&spin, Qt::Key_Up);
|
QTest::keyClick(&spin, Qt::Key_Up);
|
||||||
QCOMPARE(spin.value(), 1);
|
QCOMPARE(spin.value(), 1);
|
||||||
spin.setReadOnly(true);
|
spin.setReadOnly(true);
|
||||||
|
QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange);
|
||||||
QTest::keyClick(&spin, Qt::Key_Up);
|
QTest::keyClick(&spin, Qt::Key_Up);
|
||||||
QCOMPARE(spin.value(), 1);
|
QCOMPARE(spin.value(), 1);
|
||||||
spin.stepBy(1);
|
spin.stepBy(1);
|
||||||
QCOMPARE(spin.value(), 2);
|
QCOMPARE(spin.value(), 2);
|
||||||
spin.setReadOnly(false);
|
spin.setReadOnly(false);
|
||||||
|
QCOMPARE(spin.eventsReceived, QList<QEvent::Type>() << QEvent::ReadOnlyChange << QEvent::ReadOnlyChange);
|
||||||
QTest::keyClick(&spin, Qt::Key_Up);
|
QTest::keyClick(&spin, Qt::Key_Up);
|
||||||
QCOMPARE(spin.value(), 3);
|
QCOMPARE(spin.value(), 3);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user