Mr.Simple

http://www.qtcn.org/bbs/u/108698  [收藏] [复制]

bboyfeiyu

  • 15

    关注

  • 20

    粉丝

  • 70

    访客

  • 等级:新手上路
  • 总积分:61
  • 男,1994-02-01

最后登录:2017-09-14

更多资料

日志

关于phonon视频播放器退出全屏的解决方案

2011-10-07 18:10
     本人最近几天在学习Phonon的使用,在视频播放器上遇到了一些问题,其中相对麻烦点的是videoWidget进入全屏后用鼠标事件实现退出全屏的问题,在网上找了挺长时间无果,又去了外国的QT centre论坛还是没有找到答案,到发现遇到这个问题的老外都没有人提供解决具体解决方案。自己经过多次试验,找到了一些解决方案,特此写出来,希望能帮助到一些遇到同样问题的朋友,文章没有什么含金量。

先看看官方文档对此的描述如下:
fullScreen : boolThis property holds whether the video is shown using the complete screen.The property differs from QWidget::fullScreen in that it is writeable.By default the widget is not shown in fullScreen.Warning: When switching to full screen mode using setFullScreen(), the widget onto which the video is rendered is shown as a top-level window. Key event forwarding is handled by VideoWidget, but if you need to handle other events, e.g., mouse events, you should handle fullscreen mode yourself.Access functions:
boolisFullScreen () const
voidsetFullScreen ( bool fullscreen )

      可知当进入全屏后videoWidget成为顶级窗口,但按键事件还是有效的,然而像鼠标事件等默认情况下已经对videoWidget无效。所以可以用QAction的方法实现退出全屏,这个方法我挺早就实现了,只是想使用鼠标双击实现退出全屏,所以才在纠结。
  
   QAction方法如下:
     //   退出全屏模式的Action  
     QAction *exitFullScreenAction = new QAction(videoWidget);    
     videoWidget->addAction(exitFullScreenAction);  
     videoWidget->setAcceptDrops(true);    
     exitFullScreenAction->setShortcuts(QList<QKeySequence>() << QKeySequence(Qt::Key_Escape)<< QKeySequence(Qt::Key_MediaStop));
     connect(exitFullScreenAction, SIGNAL(triggered()), videoWidget,SLOT(exitFullScreen()));


  第二种方法是我是使用eventFilter事件过滤器的方法,首先在定义videoWidget的时候对其安装一个事件过滤器;如下:
      videoWidget = new Phonon::VideoWidget(this);  
      videoWidget->setAspectRatio(Phonon::VideoWidget::AspectRatioAuto);
      Phonon::createPath(mediaObject, videoWidget);
      videoWidget->installEventFilter(this);

  然后实现eventFilter函数:
   // 事件过滤器
bool videoPlayer::eventFilter(QObject *obj, QEvent *event)
{  
     QMouseEvent *mouse = static_cast<QMouseEvent *>(event);   //  转换为鼠标事件
     if (obj == videoWidget) {  
        // 双击实现全屏和推出全屏    
         if (event->type() == QEvent::MouseButtonDblClick) {
                if(mouse->button() == Qt::LeftButton){    
                      if(!bFull){     // 不是全屏 则进入全屏        bFull 是类成员变量  标志着是否进入了全屏  bool类型        
                                  videoWidget->enterFullScreen();
                                  bFull = true;    
                       }              
                     else{  
                            videoWidget->exitFullScreen();
                            bFull = false;  
                      }              
                   return true;      
                }      
         }      
       else          
              return false;  
      }    
     else    
          return videoPlayer::eventFilter(obj, event);
}
  当然还有其他的方法,今天回看《精通QT4编程》看到类似的解决方法有五种,不过也是刚看到的,具体怎么实现没有试验过,有朋友提供好的方法本人非常感谢。本人是新人,接触QT时间很短,也没有学过C++、java之类的,如果有错望大家见谅。


贴一下效果图吧:                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 



分类:默认分类|回复:4|浏览:3135|全站可见|转载
 
 
删除

lastforever:我也一直纠结这个问题啊,想用鼠标控制视频全屏和暂停的,可是一直实现不了,没想到用事件过滤器,我也是初学者呀,不懂得还得问问楼主,我的QQ:1017268465@qq.com,希望能交流交流,谢谢啦!

2013-05-14 23:05 -
删除

duduqq:你的phonon如何支持播放mp4之类的视频啊,要想支持更多的格式又要怎么做。

2011-11-16 20:31 -

bboyfeiyu:安装解码包,win7 codec

2011-11-17 09:29

bboyfeiyu:解码包

2011-11-17 09:30

Powered by phpwind v8.7 Certificate Copyright Time now is:04-29 09:55
©2005-2016 QTCN开发网 版权所有 Gzip disabled