summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qcombobox.cpp
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2012-12-18 00:31:11 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-05-27 15:19:41 +0200
commitcada1fb4ef04b64593156be1190884c314d7c041 (patch)
tree5a57ed170b15fa05754b3592641f945bd273f222 /src/widgets/widgets/qcombobox.cpp
parent24466d354219048b808393a094fcf80ae5c99e39 (diff)
Add QComboBox::currentData
Convenience function that returns user data for the current item, analogous to currentText(). This avoids to having to write the cumbersome QVariant variant = comboBox->itemData(comboBox->currentIndex()); (It's quite common to put strings as text and the corresponding enum values as user data.) Change-Id: I8c7632c647c5583d18e4e22703aeb4447d73162d Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/widgets/widgets/qcombobox.cpp')
-rw-r--r--src/widgets/widgets/qcombobox.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index 6103b9b4c2..6424ee41f1 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -2066,6 +2066,20 @@ QString QComboBox::currentText() const
}
/*!
+ \property QComboBox::currentData
+ \brief the data for the current item
+ \since 5.2
+
+ By default, for an empty combo box or a combo box in which no current
+ item is set, this property contains an invalid QVariant.
+*/
+QVariant QComboBox::currentData(int role) const
+{
+ Q_D(const QComboBox);
+ return d->currentIndex.data(role);
+}
+
+/*!
Returns the text for the given \a index in the combobox.
*/
QString QComboBox::itemText(int index) const