But I don't inherit from QWidget, I inherit from QObject. How can I use this functionality since it is for QWidget only? Thanks.
But I don't inherit from QWidget, I inherit from QObject. How can I use this functionality since it is for QWidget only? Thanks.
ToddAtWSU (27th September 2007)
I have a QGLWidget that is a plot. I then have numerous QObjects that I add to the QGLWidget. The one class I have is to display some sort of "marker line" on the plot and it has some OpenGL drawing code that it performs by setting up its viewport onto a specific portion of the QGLWidget. But this "marker line" is just a QObject. So I guess I can capture when the mouse is over the QGLWidget and go through the marker lines and if it the mouse is on top of one, then change the cursor. So this will work for me now that I think about it a little more.
Thanks!
I have been thinking about this and came up with another problem. Sure I can check when the mouse enters the widget and when the mouse leaves the widget, but can I track when the mouse moves around the widget after entering it and before leaving it? Since I only want to change the mouse cursor over a portion of my widget, is there a way to track the mouse during its movement over the widget? Do I just need to turn on mouse tracking with the setMouseTracking function? Or do I need to do more things? Thanks!
The docs are your friend!
void QWidget::mouseMoveEvent ( QMouseEvent * event ) [virtual protected]
This event handler, for event event, can be reimplemented in a subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
QMouseEvent:os() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.
http://doc.trolltech.com/4.3/qwidget.html#moveEvent
Last edited by momesana; 28th September 2007 at 15:53.
No I don't need the Press event to change the cursor, because I only want the cursor to change if I move over the object. I don't want to require the user to click on the plot. Is this a correct though?
I have code re-implementing mouseMoveEvent( ) and it is almost working. I have 2 QGLWidgets on my screen and I only want to be able to track the mouse on the top one. This is working, except the coordinates are WAY off. When I move over the top QGLWidget, the y-position of my mouse after I convert it to ortho coordinates is > 100,000. But my ortho only goes from 0-125. But if I click on the plot, and then move the mouse around, everything converts correctly. Is there a way to make this plot always be the "active" widget when no buttons are pushed so I can properly convert the screen coordinates to ortho coordinates? Thanks!
How do you convert those coordinates? And where is that "top QGLWidget" placed exactly?
I have a scale factor based on the width and height of the viewport in pixels, and the min and max of my ortho.
I then convert the x and y coordinates like thisQt Code:
xScaleFactor = (mXMax - mXMin) / (mViewportRight - mViewportLeft); yScaleFactor = (mYMax - mYMin) / (mViewportTop - mViewportBottom);To copy to clipboard, switch view to plain text mode
This is how I convert the coordinates, and when I print out the conversion, it's value is the ortho value I expect.Qt Code:
double x = ( event->x( ) - getLeftMarginWidth( ) ) * xScaleFactor + mXMin; double y = ( height( ) - event->y( ) - getBottomMarginHeight( ) ) * yScaleFactor + mYMin;To copy to clipboard, switch view to plain text mode
I have a QVerticalSplitter with 2 QGLWidgets in the splitter. I also have 2 toolbars left of the 2 QGLWidgets, and they are also placed in the splitter so I have something looking like
---------------------------- <-- Top Of Window
| Toolbar | QGLWidget |
---------------------------- <-- Splitter
| Toolbar | QGLWidget |
---------------------------- <-- Bottom Of Window
The top QGLWidget is the one at the top of the window. That picture above is a simple layout of what the main portion on the window looks like.
My problem is when I move over the top QGLWidget it seems like it is asking for the scale factors from the bottom QGLWidget and not the top QGLWidget. But once I click on the top QGLWidget, then everything works how I expect it to. Thanks for your continued help!
Edit:
Fixed the diagram above
Last edited by ToddAtWSU; 1st October 2007 at 18:07.
ToddAtWSU (3rd October 2007)
I set them upon creation of the QGLWidget. I have some other functions that get called by the constructor and create the data set that goes and calculates my mins, maxs, widths, and heights for all my different objects. But it looks like I might not be storing my mins and maxs like I thought I was...so I will look more deeply into this and let you know if this is what it is. Thanks a whole lot!!!
Bookmarks