qt - Mouse events blocked because of QGL View -


i created simple project show problem have in bigger application.
so, create mainwindow 2 buttons. create class inherit qwidget 2 buttons , qgl view.
problem that, apparently , reason don't find, creation of qgl view blocks events of views, particularly mouse events. in code below, mouse hover events on buttons , main widget of class 1 not detected (the cursor has change arrow hand , wait respectively) whereas mouse cursor changes on mainwindow buttons (but in real application, it's more serious simple hover event).
precise problem appears on mac 10.6 , superior, , not on windows. use qt 5.1.

here code :

mainwindow.h :

#ifndef mainwindow_h #define mainwindow_h  #include <qmainwindow>  class class1; class panoramaglview;  namespace ui { class mainwindow; }  class mainwindow : public qmainwindow {     q_object  public:     explicit mainwindow(qwidget *parent = 0);     ~mainwindow();  private:     ui::mainwindow *ui;     class1 *c1;     panoramaglview *gl; };  #endif // mainwindow_h 

mainwindoww.cpp :

#include "mainwindow.h" #include "ui_mainwindow.h"  #include <iostream> using namespace std;  #include "class1.h" #include "panoramaglview.h"  mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);      c1=new class1(0);     ui->centrallayout->addwidget(c1);      //if created here, no problem mouse cursor on mainwindow buttons not want     //gl=new panoramaglview(0);     //ui->centrallayout->addwidget(gl); }  mainwindow::~mainwindow() {     delete ui; } 

myglview.h :

#ifndef myglview_h #define myglview_h  #include <qgraphicsview> #include <qtopengl/qglwidget>  class myglview : public qgraphicsview {     q_object  public:     myglview(qwidget* pparent = 0);     virtual ~myglview();  protected:     qglwidget* m_pglwidget; };  #endif // myglview_h 

myglview.cpp :

#include "myglview.h"  myglview::myglview(qwidget* pparent) : qgraphicsview(pparent) {     m_pglwidget = new qglwidget(qglformat(qgl::samplebuffers | qgl::alphachannel));     m_pglwidget->makecurrent();     setviewport(m_pglwidget);      setrenderhints(qpainter::antialiasing | qpainter::smoothpixmaptransform);     setviewportupdatemode(qgraphicsview::fullviewportupdate); }  myglview::~myglview() {     delete m_pglwidget; } 

class1.h :

#ifndef class1_h #define class1_h  #include <qwidget>  class myglview;  namespace ui { class class1; }  class class1 : public qwidget {     q_object  public:     explicit class1(qwidget *parent = 0);     ~class1();  private:     ui::class1 *ui;  public slots:     void click1(); };  #endif // class1_h 

class1.cpp :

#include "class1.h" #include "ui_class1.h"  #include "myglview.h" #include <iostream> using namespace std;  class1::class1(qwidget *parent) :     qwidget(parent),     ui(new ui::class1) {     ui->setupui(this);      myglview *glv=new myglview(0);     ui->verticallayout->addwidget(glv);      connect(ui->pushbutton,signal(clicked()),this,slot(click1())); }  class1::~class1() {     delete ui; }  void class1::click1(){     cout<<"class1::click1()"<<endl; } 

mainwindow.ui :

    <?xml version="1.0" encoding="utf-8"?> <ui version="4.0">  <class>mainwindow</class>  <widget class="qmainwindow" name="mainwindow">   <property name="geometry">    <rect>     <x>0</x>     <y>0</y>     <width>400</width>     <height>300</height>    </rect>   </property>   <property name="windowtitle">    <string>mainwindow</string>   </property>   <widget class="qwidget" name="centralwidget">    <layout class="qvboxlayout" name="centrallayout">     <item>      <widget class="qwidget" name="widget" native="true">       <property name="stylesheet">        <string notr="true">background-color: rgb(255, 54, 76);</string>       </property>       <layout class="qhboxlayout" name="horizontallayout">        <item>         <widget class="qpushbutton" name="pushbutton">          <property name="cursor">           <cursorshape>pointinghandcursor</cursorshape>          </property>          <property name="text">           <string>pushbutton</string>          </property>         </widget>        </item>       </layout>      </widget>     </item>    </layout>   </widget>  </widget>  <layoutdefault spacing="6" margin="11"/>  <resources/>  <connections/> </ui> 

class1.ui :

<?xml version="1.0" encoding="utf-8"?> <ui version="4.0">  <class>class1</class>  <widget class="qwidget" name="class1">   <property name="geometry">    <rect>     <x>0</x>     <y>0</y>     <width>400</width>     <height>300</height>    </rect>   </property>   <property name="cursor">    <cursorshape>waitcursor</cursorshape>   </property>   <property name="windowtitle">    <string>form</string>   </property>   <property name="stylesheet">    <string notr="true"/>   </property>   <layout class="qvboxlayout" name="verticallayout">    <item>     <widget class="qpushbutton" name="pushbutton">      <property name="cursor">       <cursorshape>pointinghandcursor</cursorshape>      </property>      <property name="text">       <string>1</string>      </property>     </widget>    </item>    <item>     <widget class="qpushbutton" name="pushbutton_2">      <property name="cursor">       <cursorshape>pointinghandcursor</cursorshape>      </property>      <property name="text">       <string>2</string>      </property>     </widget>    </item>   </layout>  </widget>  <resources/>  <connections/> </ui> 

if don't create gl view, there no problem of course. , if create myglview instance directly in mainwindow, without class1, works too. need create différents views , not in mainwindow (which how ui created).
in opinion, it's problem way create view, parent or that, event passed parent child, think problem has link that. if works well, mouse cursor has change when mouse passes on buttons 1 , 2 (hand cursor) , hover class1 main widget (waiting cursor).

ideas?

i can confirm regression. tested on os x 10.8.4. works under qt 4.8.5, doesn't work under qt 5.1.0. should report bug. below sane single-file test case know produce next time post stackoverflow :)

//main.cpp #include <qapplication> #include <qpushbutton> #include <qstackedwidget> #include <qvboxlayout> #include <qgraphicsview> #include <qglwidget>  class testview : public qgraphicsview { public:     explicit testview(qwidget* parent = 0) : qgraphicsview(parent) {         setviewport(new qglwidget());         setscene(new qgraphicsscene(this));         scene()->addellipse(-50, -50, 100, 100, qpen(qt::red), qbrush(qt::lightgray));     } };  class pane : public qwidget { public:     explicit pane(bool hasview, const qcursor & cur, qwidget *parent = 0) :         qwidget(parent)     {         qvboxlayout * l = new qvboxlayout(this);         qpushbutton * btn = new qpushbutton("[pane]");         btn->setcursor(cur);         l->addwidget(btn);         if (hasview) l->addwidget(new testview()); else l->addstretch();     } };  class mainwindow : public qwidget {     q_object     qstackedwidget *sw; public:     explicit mainwindow(qwidget *parent = 0) : qwidget(parent) {         qvboxlayout *l = new qvboxlayout(this);         qpushbutton *btn = new qpushbutton("[main window] flip pages");         btn->setcursor(qt::pointinghandcursor);         connect(btn, signal(clicked()), slot(nextpage()));         sw = new qstackedwidget();         l->addwidget(btn);         l->addwidget(sw);         sw->addwidget(new pane(true, qt::openhandcursor));         sw->addwidget(new pane(false, qt::closedhandcursor));     }     q_slot void nextpage() { sw->setcurrentindex((sw->currentindex() + 1) % sw->count()); } };  int main(int argc, char *argv[]) {     qapplication a(argc, argv);     mainwindow w;     w.show();     return a.exec(); }  #include "main.moc" 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -