adding QWidget to Quick based application
-
@Axel-Spoerl this looks like it's what I need. I've created a class:
class DatePicker : public QQuickItem { Q_OBJECT QML_ELEMENT QCalendarWidget calendar; ...
and registered it:
qmlRegisterType<DatePicker>("DatePicker", 1, 0, "DatePicker");
and I attempt to use it:
Window { visible: true DatePicker { anchors.fill: parent }
But nothing shows up. What am I missing?
EDIT:
I also gave it a size:
DatePicker::DatePicker() { QSizeF size(300, 300); setSize(size); }
Also, I needed to use QApplication instead of QGuiApplication, because the latter gave me a runtime error:
QWidget: Cannot create a QWidget without QApplication
I'd greatly prefer to use QGuiApplication; is this possible?
Thanks...
-
@mzimmers said in adding QWidget to Quick based application:
I'd greatly prefer to use QGuiApplication; is this possible?
Since you already found out that a QWidget needs a QApplication - no.
-
@Christian-Ehrlicher OK, that's fine. I've modified my program to use QApplication, and in my QQuickItem c'tor, I've added a call to calendar.show().
Now, the calendar appears, but in a separate window. I suppose this is expected, as I create it without a parent, which according to the docs, a nullptr parent causes the c'tor to create a (new) window.
Given that I'm defining my Window in my Main.qml file, I'm not sure how to give the calendar the appropriate parent. Is there away to do this, or must I define my main window using a QQuickItem as well?
Thanks...
-
@mzimmers
from @kkoehne here: https://forum.qt.io/topic/92859/how-to-embed-qwidget-into-qml/2
It is only supported it the other way round: Embedding a Qt Quick scene in QWidgets, either through QQuickView, QQuickWidget, or QWidget::createWindowContainer().Ask @kkoehne about it. The post is old.
-
Hi,
KDAB has created the DeclarativeWidgets project to integrate widgets in QtQuick applications.
-
@SGaist @JoeCFD thanks for the information.
That KDAB project is huge, and it doesn't appear to have been updated recently (which might be OK).
If this truly is such a major effort, I suppose I'm better off just implementing my own date picker QML component. I have to say that I'm a bit surprised that Qt doesn't have one.
-
@mzimmers said in adding QWidget to Quick based application:
implementing my own date picker QML component. I have to say that I'm a bit surprised that Qt doesn't have one
Remember I know nothing about QML. Or whether "QtQuick" matters. But why aren't:
- https://doc.qt.io/qt-5/qml-qtquick-controls-calendar.html
- https://felgo.com/doc/felgo-datepicker/
- https://stackoverflow.com/questions/74930721/how-to-build-a-scrollable-date-picker-in-qml
etc. "QML date pickers"? Hmm, maybe "QML component" isn't any good for "QtQuick" ....
-
@JonB thanks for the update - the last time I looked, Qt 6 didn't have the QML calendar (at least it wasn't documented in the normal location). Now, it appears that it does. I can probably use that and the MonthGrid, and a few other things to make my own (essentially what the SO article you referenced does). The felgo example doesn't look right for me -- I need a real calendar.
I'll start playing with the tools I'm given...thanks again.
-
@JonB your first bullet point is the closest to anything officially supported by Qt. However it is in Quick Controls 1 which got deprecated towards the end of Qt 5 and was removed entirely from Qt 6. In Qt 5 we were encouraged to move to Quick Controls 2 but it lacked a lot of basic functionality. It never offered even provided a tree view in Qt 5 for example - that only appeared relatively recently in Qt 6.
Edit: For some reason mzimmers' reply wasn't visible when I wrote this. It looks like Qt 6 does have a QML calendar after all - possibly a recent addition.
-
@Bob64 said in adding QWidget to Quick based application:
It looks like Qt 6 does have a QML calendar after all - possibly a recent addition.
Yeah - I think originally it was part of the labs stuff, then it went away, then (recently) it reappeared as part of "mainstream" Qt.
-
-
Perhaps a preview toggle would be useful as to prevent clutter while choosing layout while still having the option to see the result before confirming. I would recommend using icons instead of words for the preview toggle and confirmation button as the idea's theme is about order and aesthetics.