Results 1 to 3 of 3

Thread: How to get Phonon::VideoPlayer video size

  1. #1
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How to get Phonon::VideoPlayer video size

    Hi everyone,

    I'm back with a new question.
    I have a dialog box which has a button to call QFileDialog::getOpenFileName() to choose a video file.
    And the Phonon::VideoPlayer will use the path to play the video.
    Now I want to get the width and height of the video. After some searching I try to use VideoPlayer->sizeHint()to get the size while the path is set. The code is like:

    Qt Code:
    1. void VideoDialog::addVideo() // A slot called by clicked() signal of the button
    2. {
    3. QMessageBox::warning(this, tr("0"), QString::number(m_videoPlayer->sizeHint().width()) + " x " + QString::number(m_videoPlayer->sizeHint().height()));
    4. QString videoFile = QFileDialog::getOpenFileName(.....); // The function arguments are removed
    5. if(!videoFile.isEmpty()){
    6. m_videoPlayer->mediaObject()->clear();
    7. m_videoPlayer->mediaObject()->setCurrentSource(videoFile);
    8. QMessageBox::warning(this, tr("1"), QString::number(m_videoPlayer->sizeHint().width()) + " x " + QString::number(m_videoPlayer->sizeHint().height()));
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    The problem I met is that after I set the video path, the sizeHint is not updated. But if I press the button again, the sizeHint will be the right value. Is there a way to get the sizeHint immediately?
    Thanks in advance.

  2. #2
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get Phonon::VideoPlayer video size

    And another thing I found is when I hide the VideoPlayer widget, I only get 1 x 1 every time on sizeHint.
    I know the doc says "The default implementation of sizeHint() returns an invalid size if there is no layout for this widget. "
    But I do need to hide the widget on initial. Any help please?

  3. #3
    Join Date
    Jul 2012
    Posts
    53
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to get Phonon::VideoPlayer video size

    Please ignore my last reply, I think it is caused by I didn't load the video first.

    So Back to my original question, after I load my video, I cannot get the size directly.
    I solved it by getting size after the hasVideoChanged() signal.

    Now I can get the size of the 1st video. But if I change it to another video, even if the hasVideoChanged() signal is emitted, the video player's sizeHint is keeping the old value.
    I can solve it by doing
    Qt Code:
    1. videoPlayer->show();
    2. videoPlayer->sizeHint();
    3. videoPlayer->hide();
    To copy to clipboard, switch view to plain text mode 
    But obviously that's not a good way since I want the player keeping hidden.
    This there a way to solve this?
    Thanks.

Similar Threads

  1. phonon videoplayer and frame
    By Kethan Kumar in forum Qt Programming
    Replies: 0
    Last Post: 17th February 2012, 05:09
  2. Phonon::VideoPlayer
    By dano_labrosse in forum Newbie
    Replies: 6
    Last Post: 1st February 2012, 06:33
  3. QGraphicsEffect on a Phonon::VideoPlayer
    By scary_jeff in forum Newbie
    Replies: 3
    Last Post: 20th January 2011, 01:12
  4. How to set a background in a Phonon VideoPlayer ?
    By slimIT in forum Qt Programming
    Replies: 1
    Last Post: 24th October 2010, 21:54
  5. Phonon - videoPlayer Error
    By uGin in forum Qt Programming
    Replies: 1
    Last Post: 22nd July 2010, 10:09

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.