diff --git a/src/controls/QskComboBox.cpp b/src/controls/QskComboBox.cpp index 84f1cc69..6aaea92a 100644 --- a/src/controls/QskComboBox.cpp +++ b/src/controls/QskComboBox.cpp @@ -92,7 +92,7 @@ namespace class QskComboBox::PrivateData { public: - QPointer < QskPopup > menu; + QPointer < QskMenu > menu; QVector< Option > options; QString placeholderText; @@ -244,6 +244,12 @@ QString QskComboBox::currentText() const void QskComboBox::openPopup() { + /* + maybe we should implement an alternative implementation + using a QskSelectionDialog, that could be en/disabled + by setting a mode TODO ... + */ + if ( m_data->menu ) return; @@ -261,6 +267,9 @@ void QskComboBox::openPopup() for ( const auto& option : m_data->options ) menu->addOption( option.graphic, option.text ); + connect( menu, &QskMenu::currentIndexChanged, + this, &QskComboBox::indexInPopupChanged ); + connect( menu, &QskMenu::triggered, this, &QskComboBox::setCurrentIndex ); @@ -408,4 +417,12 @@ int QskComboBox::count() const return m_data->options.count(); } +int QskComboBox::indexInPopup() const +{ + if ( m_data->menu ) + return m_data->menu->currentIndex(); + + return -1; +} + #include "moc_QskComboBox.cpp" diff --git a/src/controls/QskComboBox.h b/src/controls/QskComboBox.h index 92bf38e4..eadb8f9a 100644 --- a/src/controls/QskComboBox.h +++ b/src/controls/QskComboBox.h @@ -17,13 +17,17 @@ class QSK_EXPORT QskComboBox : public QskControl Q_PROPERTY( int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged ) - Q_PROPERTY( QString currentText READ currentText ) + Q_PROPERTY( QString currentText READ currentText + NOTIFY currentIndexChanged ) Q_PROPERTY( int count READ count NOTIFY countChanged ) Q_PROPERTY( QString placeholderText READ placeholderText WRITE setPlaceholderText NOTIFY placeholderTextChanged ) + Q_PROPERTY( int indexInPopup READ indexInPopup + NOTIFY indexInPopupChanged ) + using Inherited = QskControl; public: @@ -52,6 +56,9 @@ class QSK_EXPORT QskComboBox : public QskControl int currentIndex() const; QString currentText() const; + // "highlightedIndex" ( see Qt's combo boxes ) is not very intuitive + virtual int indexInPopup() const; + int count() const; QVariantList optionAt( int ) const; QString textAt( int ) const; @@ -64,6 +71,7 @@ class QSK_EXPORT QskComboBox : public QskControl Q_SIGNALS: void currentIndexChanged( int ); + void indexInPopupChanged( int ); void countChanged( int ); void placeholderTextChanged( const QString& ); @@ -77,6 +85,10 @@ class QSK_EXPORT QskComboBox : public QskControl void wheelEvent( QWheelEvent* ) override; + /* + open/close a menu - needs to be overloaded when using a custom popup + don't forget to modify indexInPopup/indexInPopupChanged as well + */ virtual void openPopup(); virtual void closePopup();