EditAble QCombobox On QML ListView! (Help Qt 4.8.4 on Windows 7)
-
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 }
}
@