This code initially somewhat draws the combobox in my QML document. But it does not seem to react on clicks or keyboard events. The paint handler is called only once.
class CountryComboBoxQmlAdapter : public QQuickPaintedItem {
Q_OBJECT
public:
explicit CountryComboBoxQmlAdapter(QQuickItem* parent = nullptr);
void paint(QPainter * painter) override;
private:
QComboBox* m_combo;
QGraphicsProxyWidget* m_proxy;
};
CountryComboBoxQmlAdapter::CountryComboBoxQmlAdapter(QQuickItem* parent) : QQuickPaintedItem(parent) {
setFlag(ItemHasContents, true);
m_combo = new QComboBox;
m_combo->setEditable(true);
m_combo->setFrame(false);
CountriesListModel* model = new CountriesListModel(this);
m_combo->setModel(model);
m_proxy = new QGraphicsProxyWidget;
m_proxy->setWidget(m_combo);
}
void CountryComboBoxQmlAdapter::paint(QPainter * painter) {
QStyleOptionGraphicsItem style;
style.exposedRect = this->boundingRect();
m_proxy->paint(painter, &style, m_proxy->widget());
}
↧