another setMouseTracking(true) not working; QWidget
I am trying to enable mouseTracking in a widget subclassed from QWidget. Here's the subclassed QWidget
Code:
//.h
#include <QWidget>
#include <Inventor/Qt/SoQt.h>
class Model;
{
Q_OBJECT
protected:
...
//.cpp
{
SoQt::init(this);
model = new Model(this);
this->setMouseTracking(true); //first attempt to setMouseTracking(true)
}
{
this->setMouseTracking(true); //second
qDebug("%d %d", event->x(), event->y());
}
and the constructor for the main window which instantiates the CoinWidget object:
Code:
myWindow::myWindow()
{
coinWidget = new CoinWidget;
coinWidget->setMouseTracking(true); //third
this->setMouseTracking(true); //forth
.
.
.
um, as you can see I've tried to setMouseTracking(true) 4 different ways, none of which is successful. I saw in the setMouseTracking/QCanvasView posts, you need to do it via the viewport(). But what about my example: if the widget in which you want to enable mouseTracking is subclassed from QWidget?
Re: another setMouseTracking(true) not working; QWidget
Are you trying to receive mouse move events on the coin widget?
Have you installed any event filters on it? Because usually it is not required to do this. It receives mouse move events by default...
Regards
Re: another setMouseTracking(true) not working; QWidget
Quote:
Originally Posted by
marcel
Are you trying to receive mouse move events on the coin widget?
yes, only on the CoinWidget. I want to pass event->x() and event->y() on to another part of the program. The only way I know how to get their values is to include a QMouseEvent. The problem is: I can only get the values when the mouse button is pushed. Are you suggesting there's another way to get these values, whether or not a mouse button is pushed?
Quote:
Originally Posted by
marcel
Have you installed any event filters on it? Because usually it is not required to do this.
hmmm, there are no event filters on it (unless QMouseEvent is considered a "filter").
Re: another setMouseTracking(true) not working; QWidget
So mouseMoveEvent does not get called. That is not normal.
Are you sure there is nothing covering the widget?
Perhaps more code would help.
Regards
Re: another setMouseTracking(true) not working; QWidget
mouseMoveEvent *is* getting called... but only when the button is pushed. I think I'm not using setMouseTracking(true) properly.
Re: another setMouseTracking(true) not working; QWidget
my bad (perhaps): i *do* have an event filter for the myWindow class (the main Window, in which CoinWidget is instantiated), something like:
Code:
{
if(event
->type
() == QEvent::Enter) {
if(obj == button_with_popup_widget[0])
{
panel[0]->show();
return QWidget::eventFilter(obj, event
);
}
else
{
return QWidget::eventFilter(obj, event
);
}
}
else if(event
->type
() == QEvent::Leave) {
if(if(obj == panel[0])
{
panel[0]->hide();
return QWidget::eventFilter(obj, event
);
}
else
{
return QWidget::eventFilter(obj, event
);
}
}
else
{
return QWidget::eventFilter(obj, event
);
}
}
...I wouldn't think this is the problem, though, since mousing over the CoinWidget window shouldn't be caught by this filter (which catches some mousing over specific buttons not in the CoinWidget window).
Re: another setMouseTracking(true) not working; QWidget
No, here must be it. What class is the main window? Is it QWidget or QMainWindow?
Because you should call QMainWindow::eventFilter not QWidget.
And the common practice is to test first for the target object and then for the event type, not the other way around. Take a look at the eventFilter documentation. There is an example there.
Regards
Re: another setMouseTracking(true) not working; QWidget
Quote:
Originally Posted by
marcel
No, here must be it. What class is the main window? Is it QWidget or QMainWindow?
Because you should call QMainWindow::eventFilter not QWidget.
actually, the main window class is QWidget, not QMainWindow. (I have a couple questions about this that I'll post in another thread later.) Anyway, since the main Window is a QWidget, I assume it's correct to call QWidget::eventFilter?
Quote:
Originally Posted by
marcel
And the common practice is to test first for the target object and then for the event type, not the other way around. Take a look at the eventFilter documentation. There is an example there.
I'll look more into this. The myWidget example here tests event type first, then object, but perhaps this is a special case. But this doesn't seem to be the problem, anyway: when I comment the eventFilter out of my Main Window, the mouseEvent is still behaving the same way. In other words, this function:
Code:
{
this->setMouseTracking(true);
qDebug("%d %d", event->x(), event->y());
}
is only called when I press/hold a mouseButton *before* moving the mouse. Thanks for helping me narrow it down, though...
Re: another setMouseTracking(true) not working; QWidget
I feel you still have something wrong in your eventFilter code. Did you comment out the function both in declaration and definition or just commented function body ? Try calling return QWidget::eventFilter(obj,e); in the body of event filter defined by you in the beginning itself instead of just commenting.
If everything is proper may be you have installed event filter for QApplication, did you check for this ?
The following example works fine for me
Code:
#include <QtGui>
{
public:
{
setMouseTracking(true);
}
{
te
->append
(QString("%1,%2\n").
arg(e
->pos
().
x()).
arg(e
->pos
().
y()));
}
};
int main(int argc, char *argv[])
{
Widget w;
w.show();
te->show();
return app.exec();
}
EDIT: Actually your event filter code seems to be proper(even without commenting). So my guess is there is one more event filter(may be installed on qapp) which is causing malfunction in your case.
Re: another setMouseTracking(true) not working; QWidget
...this has become hugely frustrating. Thanks, GK- yeah, your example worked for me, too. I tinkered w/the HelloGL, as well, and it works. I even included the glwidget.h/.cpp file in my own application (i replaced coinWidget with the glWidget), turned on MouseTracking, at it works.
But nothing I do with coinWidget will work! I even tried commenting the moveMouseEvent feature in the mainWindow class, then editing the mainWindow eventFilter like so:
Code:
mainWindow::mainWindow()
{
coinWidget = new CoinWidget;
coinWidget->setMouseTracking(true);
coinWidget->installEventFilter(this);
.
.
.
{
if(event
->type
() == QEvent::MouseMove) {
qDebug("eventFilter: hello");
return QWidget::eventFilter(obj, event
);
}
else
{
return QWidget::eventFilter(obj, event
);
}
}
but still only see "eventFilter: hello" if I click/drag the mouse button (on coinWidget). Other widgets with both installEventFilter() and setMouseTracking(true), however, work as expected.
So: the problem has to be my coinWidget class. This is a container widget for a coin3d scenegraph. Perhaps the SoQt widget embedded in the coinWidget is grabbing the moveMouseEvent even before Qt can? But I wouldn't think this could happen. Anyway, I'm posting the coinWidget code below. See anything???
Code:
//+++++++++++ coinwidget.h
#ifndef COINWIDGET_H
#define COINWIDGET_H
#include <QWidget>
#include <Inventor/Qt/SoQt.h>
class Model; // the class defining the coin3d geometry
{
Q_OBJECT
public:
~CoinWidget();
QSize minimumSizeHint
() const;
public slots:
void lyBG(int value);
void vuBG(int value);
void lyImgSL(int objID, int value);
void setComp(int value);
void zXagSL(int objID, int value);
void setRotAxis();
void vuSterSL();
void vuSterAcSL(int value);
void vuDrawAcSL(int value);
void vuOrthoSL();
void vuModLocSL();
signals:
protected:
// void mouseMoveEvent(QMouseEvent *event);
// above: deleted. Now only included in the mainWindow class
Model *model;
};
#endif
//+++++++++ coinwidget.cpp
#include <QtGui>
#include <QtCore>
#include <Inventor/Qt/SoQt.h>
#include <Inventor/Qt/viewers/SoQtExaminerViewer.h>
#include "coinwidget.h"
#include "model.h"
{
SoQt::init(this);
model = new Model(this);
model->setDefaultScene();
// this->setMouseTracking(true); // no longer included here;
// i do this in the mainWindow class
}
CoinWidget::~CoinWidget() { }
QSize CoinWidget
::minimumSizeHint() const { }
QSize CoinWidget
::sizeHint() const { }
void CoinWidget::vuBG(int value)
{
model->vuBG(value);
}
void CoinWidget::lyBG(int value)
{
model->lyBG(value);
}
void CoinWidget::setComp(int value)
{
model->setComp(value);
}
void CoinWidget::lyImgSL(int objID, int value)
{
model->lyImgSwi(objID, value);
}
void CoinWidget::zXagSL(int objID, int value)
{
model->set_zXag(objID, value);
}
void CoinWidget::setRotAxis()
{
model->setRotAxis();
}
void CoinWidget::vuSterSL()
{
model->vuSter();
}
void CoinWidget::vuSterAcSL(int value)
{
model->vuSterType(value);
}
void CoinWidget::vuDrawAcSL(int value)
{
model->vuDrawType(value);
}
void CoinWidget::vuOrthoSL()
{
model->vuOrtho();
}
void CoinWidget::vuModLocSL()
{
model->vuModLoc();
}
/*
void CoinWidget::mouseMoveEvent(QMouseEvent *event)
{
qDebug("CoinWidget:: %d %d", event->x(), event->y());
}
*/
Re: another setMouseTracking(true) not working; QWidget
Quote:
This is a container widget for a coin3d scenegraph. Perhaps the SoQt widget embedded in the coinWidget is grabbing the moveMouseEvent even before Qt can?
Well, you didn't mention this before.
This is the reason. It happened to me lots of times.
The fix is to install an event filter on the child wiidget. Do what you want with the event, but make sure to forward it to the child, in case it needs it.
Regards
Re: another setMouseTracking(true) not working; QWidget
I was all set to donate a few kopeks to the Ceauseascu Center for Historical Revisionism in your honor... when I realized I don't know what you're talking about (yet).
When you say
Quote:
install an event filter on the child wiidget.
...make sure to forward it to the child
I tried that (i think), above: "coinWidget->installEventFilter(this);" ...or what am I missing?
Re: another setMouseTracking(true) not working; QWidget
Forget Ceausescu :).
What you're missing (I think) is that you have to install an event filter for the widget contained within the coin widget(I don't know what is called), because that is the one that's eating all the mouse move events for your widget.
So, what do you have inside the coin widget?
Regards
Re: another setMouseTracking(true) not working; QWidget
the coinWidget constructor is basically:
Code:
{
SoQt::init(this); // initializing the coin3d render window
model = new Model(this); // the coin3d scenegraph
model->setDefaultScene(); // set up default 3d scene
}
and the constructor for Model:
Code:
Model
::Model( QWidget *parent,
const char * name,
const SbBool embed
) : SoQtExaminerViewer( parent, name, embed, SoQtFullViewer::BUILD_POPUP, SoQtViewer::BROWSER, TRUE)
{
QWidget *widget
= this
->buildWidget
(this
->getParentWidget
());
this->setBaseWidget(widget);
}
so you're suggesting that I add an eventFilter to the Model class to intercept the mouseMovements? I'll try this. It does seem odd that I can intercept the mouseMovements at the application/mainWindow level, but only if the mouse-button is pushed/dragged.
ok, we'll bag Ceauseascu for now. ...maybe Vlad?;) I just listened to a podcast about the famed Impaler a couple days ago. tisk tisk: everyone knows the humane way to slaughter folks is from a B-52.:rolleyes: (sorry, gettin' off-topic here)
Re: another setMouseTracking(true) not working; QWidget
Install the event filter on the baseWidget of Model.
Does it have a getter for it?
Regards
Re: another setMouseTracking(true) not working; QWidget
I don't understand what the BaseWidget is. It looks to me like in:
QWidget *widget = this->buildWidget(this->getParentWidget());
widget is a pointer to the coinWidget class/object? So
this->setBaseWidget(widget);
is setting baseWidget to the coinWidget? I don't know what a getter is.
Re: another setMouseTracking(true) not working; QWidget
Quote:
void SoQtComponent::setBaseWidget(QWidget * widget) [protected]
Set the core widget for this SoQt component. It is important that subclasses get this correct, as the widget set here will be the widget returned from query methods.
from the SoQtExaminerViewer documentation.
EDIT: isn't "the widget set here" in my case the CoinWidget?
Quote:
QWidget * SoQtFullViewer::buildWidget (QWidget * parent ) [protected]
This method builds the component contents in the given parent widget. For subclasses adding new user interface items, this method is typically overridden in the following manner:
QWidget * MyOwnViewer::buildWidget(QWidget * parent)
{
QWidget * superw = <superclass>::buildWidget(parent);
// [then move superw within MyOwnViewer framework and add own
// user interface components]
}
Re: another setMouseTracking(true) not working; QWidget
If it has a setter( setBaseWidget) then it also should have a getter( getBaseWidget or baseWidget).
You need a function in the model that returns the widget created in the constructor( widget ). The event filter has to be installed on that widget.
Regards
Re: another setMouseTracking(true) not working; QWidget
gotcha. yeah, there's a getBaseWidget.
Re: another setMouseTracking(true) not working; QWidget
I've sort of been watching this thread from a distance. I'm at work a the moment so I can't view the Coin3d, or the code we played with a while back, source, but in the original thread starter on http://www.qtcentre.org/forum/f-newb...lots-6895.html you used to have a line
Code:
SoQtExaminerViewer *eviewer = new SoQtExaminerViewer(this);
that created a SoQtExaminerViewer within the CoinWidget. This effectively overlays a coin opengl rendering window over your QWidget, and hooks in the Coin model. I've been trying to read the coin source SVN respository but its responding slowly - but its possible that on Windows this is done by subclassing the native WindowProc. The Coin3d / OIV viewers don't inherit from QWidget, so event won't bubble up the heirarchy chain - I'll take look at the coin source tonight on my pc to check how its linked in. But some of the coin examples show classes inherited from SoQt...Viewer as well as QWidget.
This might mean that trying to hook a Qt event filter won't work in this way, and this is what your seeing.
Pete
p.s Missed all the latest posts!