I need material styled replacements of standard widgets and it's kind of hard to implement them by using custom widgets. I was wondering if there's any way to include widgets from quick control module and use them as regular widgets?
Asked
Active
Viewed 1,188 times
2 Answers
4
If your application is Qt5.1 and above, the answer is yes you can.
You have to use the QQuickView
object and pass it to static function createWindowContainer
of QWidget
, which takes QWindow
as in paramater.
QQuickView
derived from QQuickWindow
which is derived from QWindow
.
So you can pass a QQuickView
as an input to the createWindowContainer
.
Below is some rough code.
//CREATE A QQuickView OBJECT.
QQuickView *view = new QQuickView();
//ADD THE QQuickView OBJECT TO QWidget::createWindowContainer
QWidget *container = QWidget::createWindowContainer(view, this);
//ADD SOURCE
view->setSource(QUrl("your.qml"));
//ADD THE CONTAINER TO YOUR LAYOUT.
ui->verticalLayout->addWidget(container);

Pavan Chandaka
- 11,671
- 5
- 26
- 34
2
You can use QQuickWidget
if you want to insert your QML view in a layout :
//CREATE THE QQuickWidget
QQuickWidget *quickWidget = new QQuickWidget(this);
//ADD SOURCE
view->setSource(QUrl("your.qml"));
//ADD THE QQuickWidget TO YOUR LAYOUT.
ui->verticalLayout->addWidget(quickWidget);
I adapted @katamarayudu's code to use QQuickWidget
instead of QQuickView
.

GrecKo
- 6,615
- 19
- 23