Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. EditAble QCombobox On QML ListView! (Help Qt 4.8.4 on Windows 7)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 1 Posters 1.9k Views 1 Watching
  • 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 Offline
    J Offline
    JohnDaYe
    wrote on last edited by
    #1

    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
    0
    • J Offline
      J Offline
      JohnDaYe
      wrote on last edited by
      #2

      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
      0
      • J Offline
        J Offline
        JohnDaYe
        wrote on last edited by
        #3

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

        if parent is listview, can listview auto get focus?

        1 Reply Last reply
        0
        • J Offline
          J Offline
          JohnDaYe
          wrote on last edited by
          #4

          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
          0

          • Login

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