Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    EditAble QCombobox On QML ListView! (Help Qt 4.8.4 on Windows 7)

    General and Desktop
    1
    4
    1695
    Loading More Posts
    • 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.
    • J
      JohnDaYe last edited by

      When i put a editable QCombobox on a qml listview by QGraphicsProxyWidget, it has some focus bug. when i click on QCombobox Edit Control, parent listview can not get focus, so i can not input anything..
      help me please!

      1 Reply Last reply Reply Quote 0
      • J
        JohnDaYe last edited by

        I have resovle it!

        header
        @
        #pragma once

        class CustomComboBox : public QComboBox {
        Q_OBJECT
        public:
        explicit CustomComboBox(QWidget *parent = 0) : QComboBox(parent){}

        protected:
        void focusInEvent(QFocusEvent *event)
        {
        QComboBox::focusInEvent(event);
        focusIn();
        }
        void focusOutEvent(QFocusEvent *event)
        {
        QComboBox::focusOutEvent(event);
        focusOut();
        }

        signals:
        void focusIn();
        void focusOut();
        };

        class QmlCombobox:
        public QGraphicsProxyWidget
        {
        Q_OBJECT
        public:
        QmlCombobox(QGraphicsItem *parent = NULL);
        ~QmlCombobox(void);
        static void RegsitCtrl();
        signals:
        void focusIn();
        void focusOut();
        private:
        CustomComboBox *m_pCtrl;
        };
        @

        cpp

        @
        #include "StdAfx.h"
        #include "QmlCombobox.h"

        QmlCombobox::QmlCombobox(QGraphicsItem* parent): QGraphicsProxyWidget(parent)
        {
        m_pCtrl = new CustomComboBox(NULL);
        m_pCtrl->setEditable(true);
        setWidget(m_pCtrl);
        QObject::connect(m_pCtrl, SIGNAL(focusIn()), this, SIGNAL(focusIn()));
        QObject::connect(m_pCtrl, SIGNAL(focusOut()), this, SIGNAL(focusOut()));
        }

        QmlCombobox::~QmlCombobox(void)
        {
        }

        void QmlCombobox::RegsitCtrl()
        {
        int n = qmlRegisterType<QmlCombobox>("NativeWidgets", 1, 0, "QmlCombobox");
        }
        @

        qml
        @
        import QtQuick 1.1
        import NativeWidgets 1.0

        Rectangle {
        width: 300
        height: 300

        VisualItemModel {
            id: mymodel
            Rectangle {
                height: 30
                width: 100
                objectName: "cmb1"
                QmlCombobox {
                    height: 30
                    width: 100
                    onFocusIn: {
                        list_test.focus = true
                    }
                }
            }
            Rectangle {
                height: 30
                width: 100
                QmlCombobox {
                    objectName: "cmb2"
                    height: 30
                    width: 100
                    onFocusIn: {
                        list_test.focus = true
                    }
                }
            }
        }
        
        ListView {
            id: list_test
            objectName: "list"
            width: 100
            height: 100
            model: mymodel
        }
        

        }
        @

        1 Reply Last reply Reply Quote 0
        • J
          JohnDaYe last edited by

          i debug and found QmlCombobox::QmlCombobox(QGraphicsItem* parent)
          parent == 0

          if parent is listview, can listview auto get focus?

          1 Reply Last reply Reply Quote 0
          • J
            JohnDaYe last edited by

            i debug and found QmlCombobox::QmlCombobox(QGraphicsItem* parent)
            parent == 0
            if parent is listview, can listview auto get focus?

            but it crash when i setParent to QmlCombobox

            1 Reply Last reply Reply Quote 0
            • First post
              Last post