pretty new to using Qt. I have a custom widget that i need to have recieving button presses, then from that button press finding the position of the mouse on the widget.
Unfortunately, currently the mousePressEvent(QMouseEvent *me) doesn’t seem to be working correctly.
So i’m wondering what exactly i’m doing wrong, code below;
Header File:
#ifndef TILESHEETPANE_H
#define TILESHEETPANE_H
#include <QWidget>
#include "global.h"
class tileSheetPane : public QWidget
{
Q_OBJECT
public:
tileSheetPane(int scnWidth, Global *global, QWidget *parent);
protected:
void mousePressEvent(QMouseEvent *me);
void paintEvent(QPaintEvent *);
private:
Global *tempGlobal;
QPoint cursorPos;
int tileSheetPaneWidth, tileSheetPaneHeight, renderOffsetY;
};
#endif // TILESHEETPANE_H
Src File:
#include <QPainter>
#include <QMouseEvent>
#include "tilesheetpane.h"
//Constructor & Paint Event ..
void tileSheetPane::mousePressEvent(QMouseEvent *me)
{
cursorPos = me->pos();
}
CursorPos’s values just say at their initialized 0. So any help would be greatly appreciated :), as i said, pretty new to using QT only started probably 2 days ago so i’m still trying to figure out things :D.
Edit;
So after trying out some of the suggestions in the comments, nothing seems to be working. I do indeed have setMouseTracking(true) but still nothing. I inserted a qDebug call into the function as suggested and it seems that the mousePressEvent never gets called.
void tileSheetPane::mousePressEvent(QMouseEvent *me)
{
cursorPos = me->pos();
//These Never Show Up!
qDebug() << me->pos().x();
qDebug() << me->pos().y();
}
Something perhaps is blocking or stopping this being called but im not sure what it could be?
So i just couldn’t get the mouse clicking working, so after doing some searching on google, i eventually found the following video;
http://www.youtube.com/watch?v=E29KiTRYpjk
As my widget is rather small anyway, i basically just re-did the entire thing. But it was worth it.
Essentially i deleted my old files, created a Qt Designer Form, added in a new widget into my mainWindow.ui file, promoted it to use “tileSheetPane” and that’s it. Works perfectly now :D.