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. Enter/Leave events are not emitted
Forum Updated to NodeBB v4.3 + New Features

Enter/Leave events are not emitted

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.5k Views 1 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.
  • M Offline
    M Offline
    MadWatch
    wrote on last edited by
    #1

    Greetings.

    I've made my own custom widget to embed Ogre into Qt. It's a simple QWidget from which I get the winId and pass it to Ogre. It works pretty well, except for one thing: I don't always get the enter and leave events when the mouse enters and leaves it (I would say I get them one time out of ten). The underMouse() method also always returns false. However the mouse move event works perfectly.

    Here is the (minimal) code:
    @
    class OgreWidget : public QWidget
    {
    Q_OBJECT

    private:
    OgreStuff* mOgre;
    Ogre::RenderWindow* mRenderWindow;
    Ogre::Viewport* mViewport;
    Ogre::Camera* mCamera;

    void initOgre();
    
    virtual QPaintEngine* paintEngine() const;
    virtual void showEvent(QShowEvent* evt);
    virtual void paintEvent(QPaintEvent* evt);
    virtual void resizeEvent(QResizeEvent* evt);
    virtual void mouseMoveEvent(QMouseEvent* evt);
    virtual void leaveEvent(QEvent* evt);
    

    public:
    OgreWidget(QWidget* parent = 0, Qt::WindowFlags f = 0);
    ~OgreWidget();
    };

    OgreWidget::OgreWidget(QWidget* parent, Qt::WindowFlags f)
    : QWidget(parent, f)
    {
    setContextMenuPolicy(Qt::DefaultContextMenu);
    setFocusPolicy(Qt::WheelFocus);
    setMouseTracking(true);
    setAttribute(Qt::WA_PaintOnScreen);
    setAttribute(Qt::WA_NoSystemBackground);
    }

    OgreWidget::~OgreWidget()
    {
    delete mOgre;
    }

    void OgreWidget::initOgre()
    {
    // Create Ogre
    mOgre = new OgreStuff();
    // Get id of the existing window created by Qt
    Ogre::NameValuePairList params;
    params["parentWindowHandle"] = Ogre::StringConverter::toString((unsigned long)winId());
    // Create render window
    mRenderWindow = mOgre->root->createRenderWindow("MyWindow",
    width(),
    height(),
    false,
    &params);
    // Create viewport
    mViewport = mRenderWindow->addViewport(0, 0);
    }

    QPaintEngine* OgreWidget::paintEngine() const
    {
    return 0;
    }

    void OgreWidget::showEvent(QShowEvent* evt)
    {
    if (!mOgre)
    {
    QApplication::flush();
    initOgre();
    }
    QWidget::showEvent(evt);
    setFocus();
    }

    void OgreWidget::paintEvent(QPaintEvent* evt)
    {
    mOgre->root->_fireFrameStarted();
    mRenderWindow->update();
    mOgre->root->_fireFrameRenderingQueued();
    mOgre->root->_fireFrameEnded();
    }

    void OgreWidget::resizeEvent(QResizeEvent* evt)
    {
    if (!mRenderWindow)
    return;
    mRenderWindow->resize(width(), height());
    mRenderWindow->windowMovedOrResized();
    }

    void OgreWidget::leaveEvent(QEvent* evt)
    {
    cout << "LEAVE" << endl;
    evt->accept();
    }

    void OgreWidget::mouseMoveEvent(QMouseEvent* evt)
    {
    cout << "MOVE" << endl;
    evt->accept();
    }
    @

    If I comment this one line
    @params["parentWindowHandle"] = Ogre::StringConverter::toString((unsigned long)winId());@
    then Ogre renders into its own window outside of Qt and then the leave and enter events on my widget works perfectly. So this is definitely the cause of the problem. I couldn't find any solution, any idea?

    I'm on Ubuntu, I didn't try it on Windows and Mac yet. I'm using Qt 4.8.4.

    Regards.

    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