Results 1 to 3 of 3

Thread: Painting on top of QAxWidget hosted video

  1. #1
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Painting on top of QAxWidget hosted video

    I host an ActiveX control which displays video. It is wrapped in QAxWidget. I try painting within QAxWidget but it always appears behind:

    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent* e)
    2. {
    3. QMainWindow::paintEvent(e);
    4. QPainter p(this);
    5. p.setPen(Qt::red);
    6. p.drawRect(10,10,100,100);
    7. }
    To copy to clipboard, switch view to plain text mode 

    I can see the left top and left bottom corners of the rect to know it’s drawn but don’t understand how to get the z-order changed. The items are laid out in QDesigner. Below is some of the derived header from the UI compiler:

    ui_mainwindow.h
    Qt Code:
    1. centralWidget = new QWidget(MainWindow);
    2. centralWidget->setObjectName(QStringLiteral("centralWidget"));
    3. gridLayout = new QGridLayout(centralWidget);
    4. gridLayout->setSpacing(6);
    5. gridLayout->setContentsMargins(11, 11, 11, 11);
    6. gridLayout->setObjectName(QStringLiteral("gridLayout"));
    7. HDVideo = new QAxWidget(centralWidget);
    8. HDVideo->setControl(QStringLiteral("{cb1671db-6c24-4c48-b5f9-8276d135501e}"));
    9. HDVideo->setObjectName(QStringLiteral("HDVideo"));
    10.  
    11. gridLayout->addWidget(HDVideo, 0, 0, 1, 1);
    To copy to clipboard, switch view to plain text mode 

    I’ve tried calling ui->HDVideo->lower as well as ui->HDVideo->stackUnder(this) which doesn’t work. How can you paint on a QAxWidget?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Painting on top of QAxWidget hosted video

    Do you call QMainWindow::setCentralWidget() somewhere with your centralWidget pointer?

    In your paintEvent() method, you are painting on the MainWindow, not the QAxWidget. Z-order is defined for sibling widgets. The QAxWidget is a child of the MainWindow widget and so will always appear in front of it.

    If you want your painting to appear as if it was on top of the QAxWidget, then you either need to derive your own widget from QAxWidget and override the paintEvent() to do your drawing there (after the QAxWidget has painted its contents), or create a transparent widget (QWidget::setWindowOpacity()) that is a sibling of the QAxWidget and set its size, position, and z-order to sit exactly on top of the QAxWidget (QWidget::raise() or QWidget::stackUnder()). Do your drawing on the transparent widget. You'll have to handle resize events on the main window to make sure the transparent window is always in sync with the video widget.

    I don't know if you can derive from QAxWidget and make it work properly. QAxWidget is a wrapper around ActiveX controls. For painting, Qt provides a window in which the control can paint (or vice-versa - Qt hosts the control's window in the QAxWidget). The control's painting may not be handled by or synchronized with Qt's paintEvent().

  3. #3
    Join Date
    Oct 2012
    Location
    The land of pain (NY)
    Posts
    99
    Thanks
    7
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Windows Android

    Default Re: Painting on top of QAxWidget hosted video

    Quote Originally Posted by d_stranz View Post
    Do you call QMainWindow::setCentralWidget() somewhere with your centralWidget pointer?

    In your paintEvent() method, you are painting on the MainWindow, not the QAxWidget. Z-order is defined for sibling widgets. The QAxWidget is a child of the MainWindow widget and so will always appear in front of it.

    If you want your painting to appear as if it was on top of the QAxWidget, then you either need to derive your own widget from QAxWidget and override the paintEvent() to do your drawing there (after the QAxWidget has painted its contents), or create a transparent widget (QWidget::setWindowOpacity()) that is a sibling of the QAxWidget and set its size, position, and z-order to sit exactly on top of the QAxWidget (QWidget::raise() or QWidget::stackUnder()). Do your drawing on the transparent widget. You'll have to handle resize events on the main window to make sure the transparent window is always in sync with the video widget.

    I don't know if you can derive from QAxWidget and make it work properly. QAxWidget is a wrapper around ActiveX controls. For painting, Qt provides a window in which the control can paint (or vice-versa - Qt hosts the control's window in the QAxWidget). The control's painting may not be handled by or synchronized with Qt's paintEvent().
    Though not explicitly shown, since I mentioned that the layout was done in designer, the call to setCentralWidget is made in the ui header file. The specific call is here:

    Qt Code:
    1. HDVideo = new QAxWidget(centralWidget);
    2. HDVideo->setControl(QStringLiteral("{cb1671db-6c24-4c48-b5f9-8276d135501e}"));
    3. HDVideo->setObjectName(QStringLiteral("HDVideo"));
    4. HDVideo->setProperty("geometry", QVariant(QRect(30, 30, 221, 161)));
    5. HDVideo->setProperty("enabled", QVariant(true));
    6. MainWindow->setCentralWidget(centralWidget);
    7. HDVideo->raise();
    To copy to clipboard, switch view to plain text mode 

    Interesting that the layout places the object hosted by QAxWidget on top with the raise method. If I call lower() on the video object, it has no effect. If you would oblige me, I'm not sure what you mean by a transparent widget as a sibling of the QAxWidget. Would you mind an illustration (example snip)?
    Last edited by astodolski; 2nd September 2014 at 20:35.

Similar Threads

  1. How to access the DOM hosted within a webkit app
    By yshome in forum Qt Programming
    Replies: 1
    Last Post: 3rd August 2011, 08:02
  2. Replies: 1
    Last Post: 14th July 2010, 16:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.