Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QGraphicsProxyWidget and KeyNavigation - not a QDeclarativeItem?
QtWS25 Last Chance

QGraphicsProxyWidget and KeyNavigation - not a QDeclarativeItem?

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tedmiddleton
    wrote on last edited by
    #1

    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>
    #endif

    class 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_box

    It'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?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tedmiddleton
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved