QGraphicsProxyWidget and KeyNavigation - not a QDeclarativeItem?
-
I'm using Qt 4.8.4 on Windows and OSX. I have a QGraphicsProxyWidget that wraps a combobox.
@#ifndef STDCOMBOBOX_H
#define STDCOMBOBOX_H#ifdef QML_TESTBED
#include <QComboBox>
#include <QGraphicsProxyWidget>
#else
#include <QtGui/QComboBox>
#include <QtGui/QGraphicsProxyWidget>
#endifclass StdComboBox : public QGraphicsProxyWidget
{
Q_OBJECT
Q_PROPERTY( int count READ count )
Q_PROPERTY( int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged )
Q_PROPERTY( QString currentText READ currentText NOTIFY currentTextChanged )
Q_PROPERTY( int maxCount READ maxCount WRITE setMaxCount )
Q_PROPERTY( QAbstractItemModel * model READ model WRITE setModel )
//Q_PROPERTY( bool focus READ focus WRITE setFocus NOTIFY focusChanged )
public:
StdComboBox(QGraphicsItem *parent = 0);
virtual ~StdComboBox();int count() const; int currentIndex() const; QString currentText() const; int maxCount() const; QAbstractItemModel * model() const; bool focus() const; void setCurrentIndex( int index ); void setMaxCount( int max_count ); void setModel( QAbstractItemModel * model ); void setFocus( bool focus );
signals:
void currentIndexChanged( int index );
void currentTextChanged( const QString & text );
void focusChanged();public slots:
void onCurrentIndexChanged( int index ); void onCurrentIndexChanged( const QString & text );
protected:
void focusInEvent(QFocusEvent *event);
void focusOutEvent(QFocusEvent *event);private:
QComboBox * combobox_;};
#endif // STDCOMBOBOX_H@
This renders nicely in my qml document, but I don't seem to be able to assign it to a KeyNavigation binding. I do this:
@ StdComboBox {
id: domain_combo_box
objectName: "domain_combo_box"
currentIndex: domainLoginInteraction.currentDomainIndex
anchors.left: white_rectangle.left
anchors.leftMargin: tc.midSpacing
anchors.top: security_icon.bottom
anchors.topMargin: tc.nearSpacing
anchors.right: user_name_text_input.left
anchors.rightMargin: tc.nearSpacing
height: tc.textBoxHeight
KeyNavigation.tab: user_name_text_input
KeyNavigation.backtab: previous_button
}NettoTextInput { id: user_name_text_input hintText: qsTr("Username") text: domainLoginInteraction.userName anchors.top: domain_combo_box.top anchors.right: pass_word_text_input.left anchors.rightMargin: tc.nearSpacing width: 121 KeyNavigation.tab: pass_word_text_input KeyNavigation.backtab: domain_combo_box }
@
...and what I see on the console is this:
bq. file:///C:/Users/tmiddleton/Documents/source/Tools/QMLTest/Resources/qml/DomainLoginInteraction.qml:104: Unable to assign QObject* to QDeclarativeItem*
I found a pointer to a type named class StdComboBox * , with the value (0x1f83020, name = "domain_combo_box", parent = 0x1f91d18, pos = QPointF(20, 55) , z = 0 , flags = ( ItemIsFocusable | ItemUsesExtendedStyleOption | ItemSendsGeometryChanges ) ) when looking for domain_combo_boxIt's true, though - QGraphicsProxyWidget ISN'T a QDeclarativeItem - it inherits from QGraphicsWidget => QGraphicsObject whereas QDeclarativeItem inherits from QGraphicsObject. So if KeyNavigation really does need a QDeclarativeItem, it won't find it with my proxy combobox. But is there something I'm missing here? What's the right way of doing this?
-
It sort of looks to me like I'm going to have to go through the whole business of putting a QComboBox into a QDeclarativeItem rather than a QGraphicsProxyWidget. If I've stumped the crowd here, I'm guessing that getting keyboard focus working with a QGraphicsProxyWidget would be hard.