No no no... no multiple inheritance here. If you want custom buttons, you should either subclass the buttons themselves or just create a new QStyle. It depends what you want to achieve.
No no no... no multiple inheritance here. If you want custom buttons, you should either subclass the buttons themselves or just create a new QStyle. It depends what you want to achieve.
What I want to do is have a 3D (OpenGL) object represented within a GL window that functions like a QPushbutton.
You can mouse over the 3D object and click it and it functions just like a QPushbutton. Basically, buttons in 3D rather than in 2D.
When you move the camera, move the object, rotate the object, etc. you can still click on it if it is still on screen and it will function appropriately.
I figure that if I can somehow use the QT classes for controls, I can have 3D objects that function like those controls just by using the QT code with some overridden functions here and there.
So, I need to know what functions to override, if that is possible.
Last edited by smurrish; 25th April 2006 at 10:55.
I would implement everything in a single QGLWidget here and emit signals to notify outside world about actions that are to be taken.
So, you're saying put all my objects inside
class GLScreen : public QGLWidget
{
... game objects...
}
and put the game loop code inside of the paint function I'll override in GLScreen's implementation?
I suppose I could handle the 3D button thing by having two objects for the button. One could be a QGLWidget to show it and the other could be a QPushbutton with a transparent picture so it won't be seen. I could have the QGLWidget signal the button when it's moused over and clicked. However, the button itself will have a position somewhere and it may think its been clicked when the mouse is clicked in that location on the screen. I would have to somehow disable it from getting mouse messages while still receiving messages from its associated QGLWidget.
I was hoping I could just use one object, however, by building my own button from QAbstractButton and just adding code to have it render an OpenGL textured mesh and use modified code to determine when it's been moused over and clicked.
Last edited by smurrish; 25th April 2006 at 11:27.
Yes.Originally Posted by smurrish
No. You have Qt event loop for that. paint function should just do painting.and put the game loop code inside of the paint function I'll override in GLScreen's implementation?
What do you need the QPushButton for?I suppose I could handle the 3D button thing by having two objects for the button. One could be a QGLWidget to show it and the other could be a QPushbutton with a transparent picture so it won't be seen. I could have the QGLWidget signal the button when it's moused over and clicked.
Qt Code:
//... signals: void startClicked(); void stopClicked(); void someOtherButtonClicked(); // ... }; //... GLScreen *glscr = new GLScreen(...); //... connect(glscr, SIGNAL(startClicked()), this, SLOT(startWasClickedSlot())); //...To copy to clipboard, switch view to plain text mode
smurrish (25th April 2006)
Well, I could do it that way, with individual functions in that one class all scanning for clicks in various areas and against various objects.
I just thought it would be nice for each object to figure out when it has been clicked itself and have code for handling each case in the implementation of the code for the class of that object. Also, I might want a slider for music and effects volume, and figured it would be nice to be able to use the code already implemented for that... just with a few changes to it to handle the 3D situation.
The QPushButton has all the nice stuff for being pressed, been released, only setting clicked when the mouse button was pushed and released and code for being checked or not. I would like to be able to use all that.
If I can get one of the controls classes to work, then getting all the rest to work would be very easy. Sliders, buttons, radio buttons, edit boxes, you name it. It'd be just so much better if I could make implementations of the abstract classes so each work in 3D.
I prefer having the modularity that comes with each individual class being able to handle its own domain of responsibilities, rather than having one big honking giant class having its tentacles digging into and manipulating everything.
I will look into the QEventloop class. Thank you for that.
Last edited by smurrish; 25th April 2006 at 12:33.
What do you mean by scanning for clicks? You just have to emit proper signals from within mousePressEvent of the GLWidget where you'll be checking for collisions of the mouse with various objects.Originally Posted by smurrish
What if the object has to operate on some data which is external to it? For example different buttons that turn the music on and off. You can't "embed" the music in both of them -- it has to be in an outside object, so it's better to emit a signal and handle the event in the music "handler" object.I just thought it would be nice for each object to figure out when it has been clicked itself and have code for handling each case in the implementation of the code for the class of that object.
You'll have to handle checking the value of the slider yourself anyway, so all that is left to do is to emit a signal with the slider value. You won't be able to reuse much of the code of Qt slider classes.Also, I might want a slider for music and effects volume, and figured it would be nice to be able to use the code already implemented for that... just with a few changes to it to handle the 3D situation.
But you'll have to check all that yourself anyway. And then you just need to emit proper signals.The QPushButton has all the nice stuff for being pressed, been released, only setting clicked when the mouse button was pushed and released and code for being checked or not. I would like to be able to use all that.
The point is that they are implemented in 2D and are very dependent on that. Most of their functionality involves checking the coordinates and handling events. And you won't be able to reuse any of those. The overhead will be much greater than the gain.If I can get one of the controls classes to work, then getting all the rest to work would be very easy. Sliders, buttons, radio buttons, edit boxes, you name it. It'd be just so much better if I could make implementations of the abstract classes so each work in 3D.
You can implement your own set of "3D widgets" inside the "big honking giant" QGLWidget class, just like it's done with QWidget and widgets or QCanvas and canvas items.I prefer having the modularity that comes with each individual class being able to handle its own domain of responsibilities, rather than having one big honking giant class having its tentacles digging into and manipulating everything.
smurrish (26th April 2006)
Alright. I get you.
It'll feel more natural to me, I think, when I get used to programming Qt-style.
I appreciate your patience and time. Thank you.
Bookmarks