Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: No MouseButtonPressed/Released events with QSFMLCanvas  (Read 4071 times)

0 Members and 1 Guest are viewing this topic.

anttirt

  • Newbie
  • *
  • Posts: 3
    • View Profile
No MouseButtonPressed/Released events with QSFMLCanvas
« on: April 18, 2011, 08:02:22 am »
Hi, I'm using SFML2 (git commit 71469f18153d8a86611310684cdfdee380ad2495) and I'm having some problems with input.

I managed to draw in a Qt widget using the code from the QSFMLCanvas tutorial for 1.6 (.hpp, .cpp) and it works fine, except that I'm not getting MouseButtonPressed/Released events with PollEvent. I am however getting all sorts of other events, like MouseMoved/Entered/Left and KeyPressed/Released. I'm guessing that for some reason Qt swallows the mouse button events, but I have no idea where to start looking for the cause.

Here's my code (with my own irrelevant bits commented out):

Code: [Select]

#include "graphics/QSFMLCanvas.hpp"
// #include "graphics/Board.hpp"

#include <Qt/qapplication.h>
#include <Qt/qframe.h>
// #include <memory>
#include <iostream>

struct HayagoCanvas : QSFMLCanvas {
    HayagoCanvas(QWidget* parent, const QPoint& pos, const QSize& size, int gridSize)
        : QSFMLCanvas(parent, pos, size)
        , gridSize(gridSize)
        // , board(NULL)
    {
    }

private:
    int gridSize;
    // std::unique_ptr<Board> board;

    void OnInit() {
        // board.reset(new Board(GetWidth(), GameState(gridSize)));
    }

    void OnUpdate() {
        sf::Event event;
        while(PollEvent(event)) {
            std::cout << "Event polled: " << event.Type << std::endl;
            // if(event.Type == sf::Event::MouseButtonReleased) {
            //     board->place(ConvertCoords(GetInput().GetMouseX(), GetInput().GetMouseY()));
            // }
        }
        // board->drawBoard(*this);
        // board->drawStones(*this);
    }
};

int main(int argc, char** argv) {
    QApplication app(argc, argv);
    QFrame* frame = new QFrame;
    frame->setWindowTitle("Hayago");
    frame->resize(640, 640);
    frame->show();

    HayagoCanvas* canvas = new HayagoCanvas(frame, QPoint(20, 20), QSize(600, 600), 9);
    canvas->show();

    return app.exec();
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
No MouseButtonPressed/Released events with QSFMLCanvas
« Reply #1 on: April 18, 2011, 08:35:19 am »
Are you on Linux?
Laurent Gomila - SFML developer

anttirt

  • Newbie
  • *
  • Posts: 3
    • View Profile
No MouseButtonPressed/Released events with QSFMLCanvas
« Reply #2 on: April 18, 2011, 08:43:51 am »
Yes.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
No MouseButtonPressed/Released events with QSFMLCanvas
« Reply #3 on: April 18, 2011, 08:53:20 am »
This is an OS limitation, and I haven't found any workaround so far.
Laurent Gomila - SFML developer

anttirt

  • Newbie
  • *
  • Posts: 3
    • View Profile
No MouseButtonPressed/Released events with QSFMLCanvas
« Reply #4 on: April 18, 2011, 09:16:02 am »
Alright. I mucked about a bit and found out that I can get the missing events by adding these virtual function overrides to my canvas class:

Code: [Select]

void mousePressEvent(QMouseEvent* event) {
    std::cout << "mouse down" << std::endl;
}
void mouseReleaseEvent(QMouseEvent* event) {
    std::cout << "mouse up" << std::endl;
}


Is there any sensible way I could modify QSFMLCanvas to catch these and add them into the SFML event queue? I notice that the event queue is managed by the sf::priv::WindowImpl class which is opaque to clients of the library, so it would appear that I'd have to modify the library itself for this, but maybe I'm missing something.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
No MouseButtonPressed/Released events with QSFMLCanvas
« Reply #5 on: April 18, 2011, 09:49:43 am »
You're not missing anything, there's no way to push events with the public API.
Laurent Gomila - SFML developer

 

anything