Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. When does/should "nativeSize" change for a QGraphicsVideoItem
Forum Updated to NodeBB v4.3 + New Features

When does/should "nativeSize" change for a QGraphicsVideoItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 386 Views 2 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.
  • Chris HennesC Offline
    Chris HennesC Offline
    Chris Hennes
    wrote on last edited by
    #1

    I'm having some trouble getting through the initialization sequence of a program that displays the output of a webcam. In order to provide support for some additional features I'm using a QGraphicsVideoItem rather than the more straightforward QCameraViewfinder. However, I can't get video displaying correctly at first. I'll try to explain with the minimum of code... (assume the existence of the unexplained variables). I start with

    _videoItem = new QGraphicsVideoItem;
    _videoItem->setSize(QSize{w,h});
    _graphicsScene = new QGraphicsScene (this);
    _graphicsView = new QGraphicsView (_graphicsScene);
    _graphicsScene->addItem(_videoItem);
        connect (_videoItem, &QGraphicsVideoItem::nativeSizeChanged, this, &StopMotionAnimation::frameSizeChanged);
    

    I insert the widget into my layout and it shows a white screen in the appropriate place. Next, starting up the camera:

    _camera = new QCamera(cameras.back());
    connect (_camera, &QCamera::statusChanged, this, &StopMotionAnimation::cameraStatusChanged);
    _camera->setCaptureMode(QCamera::CaptureStillImage);
    _camera->setViewfinder (_videoItem);
    _camera->start();
    

    Then, I have the two slots, one to monitor the camera's status and one to look for changes to the nativeSize of the videoItem, which starts out at (-1,-1). The camera slot triggers just fine, executing as expected:

    void StopMotionAnimation::cameraStatusChanged(QCamera::Status status)
    {
        switch(status) {
            case QCamera::UnavailableStatus: [[fallthrough]];
            case QCamera::UnloadedStatus:    [[fallthrough]];
            case QCamera::LoadingStatus:     [[fallthrough]];
            case QCamera::UnloadingStatus:   [[fallthrough]];
            case QCamera::LoadedStatus:      [[fallthrough]];
            case QCamera::StandbyStatus:     [[fallthrough]];
            case QCamera::StartingStatus:    [[fallthrough]];
            case QCamera::StoppingStatus:
                qDebug() << "Camera status changed to " << status;
                break;
            case QCamera::ActiveStatus:
                _videoItem->show();
                _graphicsView->show();
    
                qDebug() << "QGraphicsVideoItem";
                qDebug() << "  nativeSize: " << _videoItem->nativeSize();
                break;
        }
    }
    

    The debug statement there prints out (-1,-1) when it executes the first time. However, if I basically just call the same sequence of functions a second time, the nativeSize return (640,480) and the video shows on my screen. The function connected to nativeSizeChanged never fires in any circumstance. Clearly I am doing something out of order here, but I can't figure out what it is. Any suggestions?

    Chris Hennes, Pioneer Library System

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

      Hi,

      Why show the video item before the graphics view ? AFAIK, only the second should be needed.

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

      1 Reply Last reply
      0
      • Chris HennesC Offline
        Chris HennesC Offline
        Chris Hennes
        wrote on last edited by
        #3

        I'm throwing darts at the wall to see what sticks -- since the video is not showing correctly I've tried all sorts of combinations of showing the various individual components. Right now, the only thing that works is if I create a QCameraImageCapture, attach it to the camera, and after a couple of seconds call setEncodingSettings on it, that seems to trigger the videoItem to show the image. Interestingly, even if no image is showing, that imageCapture object correctly pulls the data off of the webcam and stores it to a file.

        Chris Hennes, Pioneer Library System

        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