Page 2 of 2 FirstFirst 12
Results 21 to 28 of 28

Thread: another setMouseTracking(true) not working; QWidget

  1. #21
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    hey pdolbey- thanks for chiming in. True, I used to have that line

    Qt Code:
    1. SoQtExaminerViewer *eviewer = new SoQtExaminerViewer(this);
    To copy to clipboard, switch view to plain text mode 

    before you posted your example of how you do it, which I now follow:

    Qt Code:
    1. //++ main.cpp
    2. int main(argc, *argv[])
    3. {
    4. Window window;
    5.  
    6. //++ window.cpp
    7. Window::Window()
    8. {
    9. coinWidget = new CoinWidget;
    10.  
    11. //++ coinwidget.cpp
    12. CoinWidget::CoinWidget(QWidget *parent) : QWidget(parent)
    13. {
    14. SoQt::init(this);
    15. model = new Model(this);
    16. model->setDefaultScene();
    17.  
    18. //++ model.cpp
    19. Model::Model(QWQWidget *parent, const char * name, const SbBool embed)
    20. : SoQtExaminerViewer( parent, name, embed, SoQtFullViewer::BUILD_POPUP, SoQtViewer::BROWSER, TRUE)
    21. {
    22. QWidget *widget = this->buildWidget(this->getParentWidget());
    23. this->setBaseWidget(widget);
    To copy to clipboard, switch view to plain text mode 

    So, I'm not sure how this affects your take on this. Given this method, is "its possible that on Windows this is done by subclassing the native WindowProc" still something to worry about?

    Again, the confusing thing to me: both of the Window class event filters

    Qt Code:
    1. bool Window::eventFilter(QObject *obj, QEvent *event)
    2. // OR
    3. void Window::mouseMoveEvent(QMouseEvent *event)
    To copy to clipboard, switch view to plain text mode 

    *will* recognize the mouse Move event... but only if the button is pressed.

  2. #22
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    The coin SVN is responding better now. I've discovered some interesting code in
    http://source.coin3d.org/viewvc.py/S...pp?view=markup
    that shows up an eventFilter function that runs in a private implementation widget. Some of the comments indicate that the result your getting is not very suprising.

    Do you want to send me another code extract? Have you still got my email address?

    Pete

  3. #23
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    your email is on my infected computer--i got careless w/torrents--so no, I don't have it at the moment. But here are the files. The window, model, and coinwidget .cpp/.h files are probably the only ones relevant, but I included the others in case you want to compile. (though it'll crash at run-time without the .iv files; i need to fix this.)

    Anyway, I tried adding an eventFilter to the Model class, but as you said it doesn't inherit from QWidget.... so this:

    Qt Code:
    1. bool Model::eventFilter(QObject *obj, QEvent *event)
    2. {
    3. return QWidget::eventFilter(obj, event);
    4. }
    To copy to clipboard, switch view to plain text mode 

    causes an error when compiling: "QObject::eventFilter : illegal call of non-static member function." Perhaps there's a way around this?

    BTW, the reason I want to get the mouse Events in Qt: I'm using the SoQtExaminerViewer class for rendering. I have a function set up so that the user can mouse over the model and get the x,y,z coordinates of that spot on the model. However, it only works in selection mode, e.g.

    Model::setViewing(false);

    but I want it to work in the other mode, as well. So I figured I'd forward the mousePosition to the Model class from Qt so that the feature would work in both selection and non-selection mode. Perhaps there's an easier/better way?
    Attached Files Attached Files

  4. #24
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    But you got me all wrong.
    I suggested to install an event filter on the QWidget returned by this->buildWidget(this->getParentWidget());.

    The event filter should be the parent widget.

    Hope it's clear now.

    Regards

  5. #25
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    Oh, ok. It didn't work. I added:
    Qt Code:
    1. // model.cpp
    2.  
    3. QWidget *Model::returnBase()
    4. {
    5. QWidget *widget = this->getBaseWidget();
    6. return widget;
    7. }
    To copy to clipboard, switch view to plain text mode 

    to the Model class, and the last 2 lines below:

    Qt Code:
    1. // coinwidget.cpp
    2. CoinWidget::CoinWidget(QWidget *parent) : QWidget(parent)
    3. {
    4. SoQt::init(this);
    5.  
    6. model = new Model(this);
    7. model->setDefaultScene();
    8.  
    9. model->returnBase()->installEventFilter(this);
    10. model->returnBase()->setMouseTracking(true);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    to the CoinWidget class. I removed all eventFilters except the one in CoinWidget. As before, the eventFilter is called when I do a mouseMove event over it, but only when the mouse Button is pressed.

  6. #26
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    pdolbey- in a nutshell, I've the following callback in my coin3d code (Model class):

    Qt Code:
    1. void Model::myMouseMoveCB(void *data, SoEventCallback *eventCB)
    2. {
    3.  
    4. qDebug("...hello");
    5.  
    6. SoSeparator *root = (SoSeparator *) data;
    7. const SoEvent *event = eventCB->getEvent();
    8. const SbViewportRegion &myRegion = eventCB->getAction()->getViewportRegion();
    9. showXYZ(root, myRegion, event->getPosition(myRegion));
    10. eventCB->setHandled();
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    The problem is: the callback is only called when

    Model::this->setViewing(false);

    This is the reason I've been pursuing the Qt route; I thought I could just send the screenPosition coordinates (over the widget) straight from Qt to Coin, but it's looking like this might not be possible.

  7. #27
    Join Date
    Nov 2006
    Location
    Shrewsbury, UK
    Posts
    97
    Thanks
    3
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    VonCZ

    According to the coin SVN repository, the SoWin viewers do exactly what I expected to see i.e. registering and creating a window with window proc, then creating a OpenGL context, but the SoQt viewers are doing some wierd and wonderful stuff with pimpl classes. If the sample you posted above can reporduce the problem I'll pull it down tonight and try debuging throught the coin code, although I'm trying to sort out some OpenCascade problems ( of my own creation ) at the moment. Otherwise, you can post it to "peter at dolbey dot freeserve dot co dot uk".

    Pete

  8. The following user says thank you to pdolbey for this useful post:

    vonCZ (6th September 2007)

  9. #28
    Join Date
    Apr 2007
    Location
    Rakovnik, Czech Republic
    Posts
    175
    Thanks
    43
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: another setMouseTracking(true) not working; QWidget

    thanks for the solution, pdolbey! Rather than re-write the email he posted, I'll quote it here:

    Basically SoQt is a rats nest of widgets, pimpls (er that's private implementations) and miscellaneous filters. Unfortunately your attempts at hacking the filters have taken a bit of a scattergun approach, but I can understand why.

    However I've attached a hack which might just work for you, only changing the Model class source files. Basically, the SoQtGLRenderArea class (a parent of SoQtExaminerViewer) sets up an eventfilter on a private widget that it processes with a processEvents method. What I've done with the Model class (even though its not technically a Qt widget) is to over-ride the processEvents method and put in a hook to the Model::mouseMoveEvent. You need to let the event still be processed by the parent classs so it can translate to the SoEvent model, but the method is defined as protected not private so this technique must be "allowed".
    and the changes/additions to the Model class are:
    Qt Code:
    1. //++++ model.h
    2.  
    3. #include <QEvent>
    4. #include <QMouseEvent>
    5.  
    6. protected:
    7. void mouseMoveEvent(QMouseEvent *event);
    8. void processEvent(QEvent *event);
    9.  
    10.  
    11.  
    12. //++++ model.cpp
    13.  
    14. void Model::mouseMoveEvent(QMouseEvent *event)
    15. {
    16. qDebug("Model:: %d %d", event->x(), event->y() );
    17. }
    18.  
    19. void Model::processEvent(QEvent *event)
    20. {
    21. if (event->type() == QEvent::MouseMove)
    22. {
    23. mouseMoveEvent ((QMouseEvent*) event);
    24. }
    25. SoQtExaminerViewer::processEvent(event);
    26. }
    To copy to clipboard, switch view to plain text mode 

    thanks again!

Similar Threads

  1. Problem with Parent QWidget and Buttons not working
    By VireX in forum Qt Programming
    Replies: 7
    Last Post: 11th May 2007, 22:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.