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. HWND in QML
Forum Updated to NodeBB v4.3 + New Features

HWND in QML

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 5 Posters 9.5k 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.
  • A Offline
    A Offline
    aliander
    wrote on last edited by
    #1

    Hi there!

    I'm trying to capture'n'display a video from a cam on QML

    At the moment I'm having a QML extension plugin containing a QGraphicsProxyWidget proxying a QWidget wich acts as a container for the Cam-API to display the video.
    Sadly the API is quite high-level, so I don't have the possibility at the moment to directly convert it to a QIODevice or something, but uses Windows' WindowHandle (HWND) to directly draw into a Window.

    I'm not quite sure, if this HWND gets lost in a QDeclarativeView, as I assume, that this is Window on its own and doesn't manage childs as seperate windows.

    Is there a possibility to draw into a qml component with HWND or is there a workaround?

    Qt Mobility seems to be not a solution, as it wasn't possible to compile it for Windows Mobile 6.5...

    Thanks in advance!
    Ali

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aliander
      wrote on last edited by
      #2

      Noone?

      Well, to cut it down:
      Is the WindowHandle of a QWidget ( winId() )still valid, when loaded as a QML ExtensionPlugin through a QGraphicsProxyWidget?

      Would be great if someone could help me out here, as I don't know where I'm wrong and this is one of the critical points ;)

      Thanks
      Ali

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moo1
        wrote on last edited by
        #3

        Using PyQt on Windows XP, I was able to create a QWidget as a child widget under a QWidget bound to QDeclarativeView, and get a valid HWND. In my case, I bound VLC player's output to the child widget, as VLC python API only accepts HWND to bind a surface. Of course, you lose all fancy stuffs from QML for the child widget but it works.

        I'm afraid QGraphicsProxyWidget doesn't return a valid HWND.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Aleskey78
          wrote on last edited by
          #4

          I had the same problem a while ago.
          I've managed to solve it by creating a hidden (setWindowOpacity(0)) window (QWidget) and a custom QML control. QId of the hidden window will get Cam-API for drawing in it and also a custom QML control that captures this window on timer and draws it on paint event:

          @void paint(QPainter *painter,
          const QStyleOptionGraphicsItem *option,
          QWidget *widget)
          {
          Q_UNUSED(option);
          Q_UNUSED(widget);

          int w = width();
          int h = height();
          
          QPixmap scaledPixmap(QPixmap::grabWindow(hwnd_).scaled(QSize(w,h),
                               Qt::KeepAspectRatio,
                               Qt::SmoothTransformation));
          
          painter->drawPixmap(x(), y(), scaledPixmap.width(), scaledPixmap.height(), scaledPixmap);
          

          }@

          You'll get the best performance when the hidden window and your QDeclarativeItem have the same size...

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

            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
            • J Offline
              J Offline
              Jianren Yin
              wrote on last edited by
              #6

              @Roman90
              Have you solved the problem ? I'm using MPlayer + QML, but failed .

              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