Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. The Lounge
  4. adding QWidget to Quick based application
QtWS25 Last Chance

adding QWidget to Quick based application

Scheduled Pinned Locked Moved Solved The Lounge
13 Posts 8 Posters 2.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I'm implementing a desktop app using QML. I finally ran across something available in a QWidget that doesn't seem to have a QML wrapper.

    I've done web searches, but haven't found anything on adding/using a QWidget class to QML code. I know that in years past, this was pretty much a non-starter, but I'm wondering whether there's anything in 6 that makes this easier.

    Thanks for any information...

    Axel SpoerlA 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I'm implementing a desktop app using QML. I finally ran across something available in a QWidget that doesn't seem to have a QML wrapper.

      I've done web searches, but haven't found anything on adding/using a QWidget class to QML code. I know that in years past, this was pretty much a non-starter, but I'm wondering whether there's anything in 6 that makes this easier.

      Thanks for any information...

      Axel SpoerlA Offline
      Axel SpoerlA Offline
      Axel Spoerl
      Moderators
      wrote on last edited by
      #2

      @mzimmers
      You may want to check the documentation of QQuickItemfor that purpose.

      Software Engineer
      The Qt Company, Oslo

      mzimmersM 1 Reply Last reply
      2
      • Axel SpoerlA Axel Spoerl

        @mzimmers
        You may want to check the documentation of QQuickItemfor that purpose.

        mzimmersM Offline
        mzimmersM Offline
        mzimmers
        wrote on last edited by mzimmers
        #3

        @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...

        Christian EhrlicherC 1 Reply Last reply
        0
        • mzimmersM mzimmers

          @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...

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by Christian Ehrlicher
          #4

          @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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          mzimmersM 1 Reply Last reply
          1
          • Christian EhrlicherC Christian Ehrlicher

            @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.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by
            #5

            @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...

            JoeCFDJ 1 Reply Last reply
            0
            • mzimmersM mzimmers

              @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...

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

              @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.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                Hi,

                KDAB has created the DeclarativeWidgets project to integrate widgets in QtQuick applications.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                mzimmersM 1 Reply Last reply
                1
                • SGaistS SGaist

                  Hi,

                  KDAB has created the DeclarativeWidgets project to integrate widgets in QtQuick applications.

                  mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #8

                  @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.

                  JonBJ 1 Reply Last reply
                  0
                  • mzimmersM mzimmers

                    @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.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by JonB
                    #9

                    @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" ....

                    mzimmersM B 2 Replies Last reply
                    0
                    • JonBJ JonB

                      @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" ....

                      mzimmersM Offline
                      mzimmersM Offline
                      mzimmers
                      wrote on last edited by
                      #10

                      @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.

                      1 Reply Last reply
                      0
                      • JonBJ JonB

                        @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" ....

                        B Offline
                        B Offline
                        Bob64
                        wrote on last edited by Bob64
                        #11

                        @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.

                        mzimmersM 1 Reply Last reply
                        1
                        • B Bob64

                          @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.

                          mzimmersM Offline
                          mzimmersM Offline
                          mzimmers
                          wrote on last edited by
                          #12

                          @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.

                          1 Reply Last reply
                          0
                          • mzimmersM mzimmers has marked this topic as solved on
                          • B Offline
                            B Offline
                            baburaoz558
                            wrote on last edited by
                            #13

                            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.

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved