Hi guys, I'm trying to create buttons inside an OpenGL scene.
I have created a class for the OpenGL window and my program opens up and displays my picture in OpenGL. I have drawn buttons on the picture and now I'm trying to get mouse click inputs recognised. I'm just using Qt's mousePressEvent to detect mouse clicks inside the OpenGL window and am using signals and slots to emit the location of the mouse click in a QPoint object.
My other class is the Button class which I will use for other purposes (hence trying to do it this way rather then just having the whole implementation done in my OpenGL class).
So anyway, here's my button class:
button.cpp
#ifndef BUTTON_H
#define BUTTON_H
#include <QWidget>
#include <QMessageBox>
#include <QMouseEvent>
{
Q_OBJECT
public:
explicit Button
(QWidget *parent
= 0);
int m_iXLocation;
int m_iYLocation;
int m_iWidth;
int m_iHeight;
Button(int iXLocation, int iYLocation, int iWidth, int iHeight) : m_iXLocation(iXLocation), m_iYLocation(iYLocation), m_iWidth(iWidth), m_iHeight(iHeight)
{}
void SetButtonParameters(int iXLocation, int iYLocation, int iHeight, int iWidth);
//virtual void mousePressEvent(QMouseEvent *event);
void ButtonClickedCheck();
signals:
public slots:
void LocationGrabber
(QPoint Location
);
};
#endif // BUTTON_H
#ifndef BUTTON_H
#define BUTTON_H
#include <QWidget>
#include <QMessageBox>
#include <QMouseEvent>
class Button : public QWidget
{
Q_OBJECT
public:
explicit Button(QWidget *parent = 0);
int m_iXLocation;
int m_iYLocation;
int m_iWidth;
int m_iHeight;
Button(int iXLocation, int iYLocation, int iWidth, int iHeight) : m_iXLocation(iXLocation), m_iYLocation(iYLocation), m_iWidth(iWidth), m_iHeight(iHeight)
{}
void SetButtonParameters(int iXLocation, int iYLocation, int iHeight, int iWidth);
//virtual void mousePressEvent(QMouseEvent *event);
void ButtonClickedCheck();
QPoint mousePosition;
signals:
public slots:
void LocationGrabber(QPoint Location);
};
#endif // BUTTON_H
To copy to clipboard, switch view to plain text mode
So as you can see... the button class the parameters which set the button dimensions and location and the only thing that it receives as input from the OpenGL window is the location of the mouse click... I haven't figured out the transformation from OpenGL coordinates to window coordinates yet, but I'm aware of it and will do so in due course.
Anyway... where should I create the instances of the buttons? Inside the constructor of the OpenGL class? or inside the constructor of the class which houses the ui? I've put in in the latter, however for some reason the signals and slots aren't picking up the clicks form the OpenGL window and my debugging message boxes aren't popping up... well to quite frank, I can't even compile it as I'm the parameters I'm inputting into connect (in order to connect slots) aren't really working. I know this has a lot of Qt related stuff, but it's still more of an object oriented question and I hope you can look past my problems with the Qt components.
mainwindow.cpp
#include "mainwindow.h"
#include "ui_mainwindow.h"
{
Button Button1(0,0,50,50);
mainwindow
::connect(mainwindowWidget,
SIGNAL(MouseClickLocation
(QPoint MousePositionAtClick
)), Button1,
SLOT(LocationGrabber
(QPoint Location
)));
ui->setupUi(this);
}
mainwindow::~mainwindow()
{
delete ui;
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
mainwindow::mainwindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::mainwindow)
{
Button Button1(0,0,50,50);
mainwindow::connect(mainwindowWidget, SIGNAL(MouseClickLocation(QPoint MousePositionAtClick)), Button1, SLOT(LocationGrabber(QPoint Location)));
ui->setupUi(this);
}
mainwindow::~mainwindow()
{
delete ui;
}
To copy to clipboard, switch view to plain text mode
Maybe I made a mistake in the connect function? Maybe I need to use references somewhere? And yes, I've included button.h in the header for mainwindow.cpp
Bookmarks