QskComboBox::indexInPopup ( a.k.a QComboBox::highlightedIndex ) added

This commit is contained in:
Uwe Rathmann 2023-03-07 15:00:33 +01:00
parent 69d43a2ffa
commit 907409f21b
2 changed files with 31 additions and 2 deletions

View File

@ -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"

View File

@ -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();