Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [UNSOLVEABLE] Again problems with QWidget in QML this time HWND

[UNSOLVEABLE] Again problems with QWidget in QML this time HWND

Scheduled Pinned Locked Moved QML and Qt Quick
15 Posts 6 Posters 11.8k Views 1 Watching
  • 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.
  • X Offline
    X Offline
    xcoder
    wrote on last edited by
    #6

    I solved my problem, the mistake was trying to use QWidget, somehow I can set the QWidget's background through CSS and it will show up in QML, but vlc won't draw anything on it.

    The solution is to use QGraphicsScene instead. Well it worked for me.

    Only a biker knows why a dog sticks his head out of a car window.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Freeuser
      wrote on last edited by
      #7

      Hi!
      I have the same problem, but I use phonon module. Can you place code with integration QGraphicsScene to Qml here? Thank you in advance!

      1 Reply Last reply
      0
      • X Offline
        X Offline
        xcoder
        wrote on last edited by
        #8

        Sorry when I made that conclusion, I thought I could implement QGraphicsSCene with valid winId, actually you can't.

        Only the main windows has valid WinId, so the VLC or maybe even phonon draws on top of the QML viewer.

        I can give you code for how to implement Qgraphicscene without winid, you will be able to draw circles rectangles or anything you want. But you won't get a valid winId.

        And if you use phonon, maybe check out Qt Multimedia. I once came across, that QML or Qt Quick has built in video/audio player. If I remember correctly the library was called Qt Multimedia.

        Only a biker knows why a dog sticks his head out of a car window.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          giesbert
          wrote on last edited by
          #9

          AFAIK, there is a possibility to fore a widget to be a real windows window. Then it will have a valid winId(). I think it was something like:

          @
          x->setAttribute(Qt::WA_NativeWindow, true);
          x->setAttribute(Qt::WA_DontCreateNativeAncestors, true);
          @

          where x is the widget that should show the video.

          as description, have a look at "native vs. alient widgets":http://doc.qt.nokia.com/latest/qwidget.html#native-widgets-vs-alien-widgets

          Nokia Certified Qt Specialist.
          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Freeuser
            wrote on last edited by
            #10

            Thanks...Unfortunately, player based on QtMobility, and Qml element "Video" are play stream video not correctly. That is why I use phonon modul. And recently I've learned that phonon player can output video to widget only...

            1 Reply Last reply
            0
            • X Offline
              X Offline
              xcoder
              wrote on last edited by
              #11

              Still, even with set attribute in qt quick my VLC plugin doesn't get a picture. If I understand correctly, when I embed QWidget in QML, it's winId technically won't exist anymore.

              Only a biker knows why a dog sticks his head out of a car window.

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Roman90
                wrote on last edited by
                #12

                Hello

                We built QML plugin that used Phonon as video play engine and it works correct in our QML project. Here are worked QML Phonon component sources:

                @ class QmlVideo : public QDeclarativeItem
                {
                Q_OBJECT
                public:
                explicit QmlVideo(QDeclarativeItem *parent = 0);
                public slots:
                void play();
                private:
                Phonon::VideoPlayer *m_pPhononPlayer;
                };
                QmlVideo::QmlVideo(QDeclarativeItem parent) :
                QDeclarativeItem(parent)
                {
                m_pPhononPlayer = new Phonon::VideoPlayer(Phonon::VideoCategory);
                QGraphicsProxyWidget
                proxy = new QGraphicsProxyWidget(this);
                proxy->setWidget(m_pPhononPlayer);
                }

                void QmlVideo::play()
                {
                    m_pPhononPlayer->play(QUrl("C:\\test.avi"));
                }
                

                @

                Now we decided to replace Phonon on another video play engine. This another video play engine draws video in external lib and requires only HWND window where to paint. So we replaced Phonon widget to usual QWidget in our QML video component and passed QWidget winId() to video lib but it doesn't work. We can hear sound but video is not visible (WM_PAINT doesn't come to this widget). Below are NOT worked QML component with using external video lib:

                @ class QmlVideo : public QDeclarativeItem
                {
                Q_OBJECT
                public:
                explicit QmlVideo(QDeclarativeItem *parent = 0);
                public slots:
                void play();
                private:
                QWidget *m_pWidget;
                IPlayerCore *m_pPlayerCore;
                };
                QmlVideo::QmlVideo(QDeclarativeItem *parent) :
                QDeclarativeItem(parent)
                {
                m_pWidget = new QWidget();
                m_pWidget->resize(300, 300);
                m_pWidget->show();

                    QGraphicsProxyWidget* proxy = new QGraphicsProxyWidget(this);
                    proxy->setWidget(m_pWidget);
                }
                 
                void QmlVideo::play()
                {
                 WId hwnd = m_pWidget->winId();
                    if (CreatePlayerCore(hwnd, &m_pPlayerCore) != IPlayerCore::STATUS_OK || m_pPlayerCore == 0) {
                        qDebug() << "Failed to create player core!\n";
                    }
                    if (m_pPlayerCore->Subscribe(new IPlayerCoreNotifyImpl(hwnd, m_pPlayerCore)) < 0) {
                        qDebug() << "Failed to subscribe to core events!\n";
                    }
                    if (m_pPlayerCore->Load(false, L"C:\\test.avi") != IPlayerCore::STATUS_OK) {
                        qDebug() << Q_FUNC_INFO << "error";
                    }
                }
                

                @

                In the same time we can see video in this m_pWidget if comment line
                //proxy->setWidget(m_pWidget);
                but then window is not part of QML scene.

                So how is to get video painted from external video lib on QWidget that will be a part of scene as QML component?

                1 Reply Last reply
                0
                • X Offline
                  X Offline
                  xcoder
                  wrote on last edited by
                  #13

                  Well, I had this problem last summer, I 've to look for my old code. I think I solved it, but I couldn't found my source code at this moment. I think it's on my other computer.

                  Only a biker knows why a dog sticks his head out of a car window.

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    Roman90
                    wrote on last edited by
                    #14

                    Could you inform me about your search results please?
                    It's urgent, for a long time already can't find the solution.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pythoneer
                      wrote on last edited by
                      #15

                      @xcoder:
                      would be nice to see a working example, still facing the same problems as you and Roman90. couldn't this be considered as a bug from qt side?

                      regards ..

                      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