ficus
ficus

Reputation: 55

components in QQuickWidget behave differently than in QQuickView

The ToolTip and ComboBox components do not close when the user clicks somewhere else on the window when using QQuickWidget, but they do close when using a QQuickView(ToolTip dissapears and the popup of the combobox closes).

Any ideas if some attributes need to be set to the QQuickWidget to have the same behaviour as the QQuickView.

UPDATE:
Clicking on the button will hide the combobox , but clicking anywhere else on the window will not make the combobox collapse.
main.cpp

int main(int argc, char *argv[])
{

    QApplication app(argc, argv);
    QQuickWidget *view = new QQuickWidget;
    view->setSource(QUrl("qrc:/resources/qml/test.qml"));
    view->show();
    return app.exec();
}

test.qml

import QtQuick 2.6
import QtQuick.Layouts 1.0
import QtQuick.Controls 2.0

Item {
id: test_combo
width: 400
height: 500
RowLayout{
   ComboBox {
        width: 200
        model: [ "Banana", "Apple", "Coconut" ]
    }

    Button{
        text: "test"
    }
    }
}

Upvotes: 0

Views: 439

Answers (1)

Parker Porfilio
Parker Porfilio

Reputation: 186

I ran into the same issue where my ComboBox's Popup would not close when I clicked elsewhere in the window if it was in a QQuickWidget.

The ComboBox behaved as I expected in a qml Window or in a QQuickView.

The solution I found was to customize the ComboBox's Popup and set the modal and closePolicy properties as follows:

ComboBox {
    popup.modal: true
    popup.closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
    model: [ "apples", "oranges", "pears" ]
}

The model there because you need a model to see the Popup in action.

Upvotes: 2

Related Questions