EditAble QCombobox On QML ListView! (Help Qt 4.8.4 on Windows 7)
-
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! -
I have resovle it!
header
@
#pragma onceclass 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.0Rectangle {
width: 300
height: 300VisualItemModel { 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 }
}
@ -
i debug and found QmlCombobox::QmlCombobox(QGraphicsItem* parent)
parent == 0if parent is listview, can listview auto get focus?
-
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