Panda 3D and Qt with C++

Hi

it was zabaki’s code that was having some trouble,
mine is doing okay; I was just giving him an example. But I’ll fix those things you suggested, thanks :slight_smile:

tim

Thank you very much for your help.

It finally worked !!! And it might have work for a while. The thing was that I used printf to test the event, and I can’t explain why but printf didn’t print anything (only in the eventHandler). I tried with cout<<…<<endl and I found out it was working.

Thank you again.
Quentin.

Hey !

I’m having the same kind of mouse problems with my QPandaWidget and none of the above helped :confused: !

Here’s the code adding the hook :

        EventHandler& events = QPandaApplication::Framework().get_event_handler();

        bool er = true;

        er = er && events.add_hook("mouse1",    QPandaWidget::CallbackButton1,   this);
        er = er && events.add_hook("mouse2",    QPandaWidget::CallbackButton2,   this);
        er = er && events.add_hook("mouse3",    QPandaWidget::CallbackButton3,   this);
        er = er && events.add_hook("mouse1-up", QPandaWidget::CallbackButtonUp1, this);
        er = er && events.add_hook("mouse2-up", QPandaWidget::CallbackButtonUp2, this);
        er = er && events.add_hook("mouse3-up", QPandaWidget::CallbackButtonUp3, this);
        if (er == false)
        {
            std::cout << "Failed to add hooks" << std::endl;
            exit(-1);
        }
void      QPandaWidget::CallbackButton1  (const Event*, void* ptr)
{
    std::cout << "CallbackButton1 said: It works !" << std::endl;
    reinterpret_cast<QPandaWidget*>(ptr)->EmitSignalPressed(1);
}

It’s only for test purpose right now, but it should work nevertheless. As far as I know (it’s basically just a copy-paste of what I did in a Panda3D-standing alone application).
Yet I have absolutely no error message (every call to add_hook also returns true) or no indication that something is happening : the callbacks are simply never called (and I’m already using std::cout to check this :wink: ).

I also tried using the global_event_handler().

Also, this code is executed after the creation of the window (I don’t know if it has any influence but just in case…).

I can confirm that it has to come from me because the setup_trackball works just fine, and I can get mouse positions whenever I want to : the only thing I can’t get is my hooks being called when there is a click.
Where could I have go wrong here ?

Hi again

by chance did you do a window->enable_keyboard(); before going into a main loop ?

If I don’t do that little bit of “magic” it doesn’t work for me either… Not sure why doing a enable_keyboard has anything to do with the mouse events but it seems to have some positive effect.

So, if you don’t have it, then put it in there and see what happens.

Hope this helps

Yeah, I actually found out yesterday totally by chance when I tried using keyboard events (but my Internet connection went numb and I couldn’t come here to yell my happiness).

It’s… weird oO. So, yeah ! It works now ! Thanks !