QPushButton board
-
Hello, you need to do a board where you can click a button and it tells me to coordinate the board is that button.
I am new in Qt and i use QtCreator, not as I can make a matrix of buttons in the editor or something that not many buttons on a layout, any ideas?
regards
-
You could use a "QSignalMapper":http://doc.qt.nokia.com/4.7/qsignalmapper.html and connect all buttons with a "QSignalMapper":http://doc.qt.nokia.com/4.7/qsignalmapper.html and map the id to coordinates.
Or you use QPushButtons and "dynamic properties,":http://doc.qt.nokia.com/4.7/qobject.html#dynamic-properties connect all buttons to the same slot and use sender() to get the button and read the "dynamic property.":http://doc.qt.nokia.com/4.7/qobject.html#dynamic-properties
Or you create a subclassed button which gets the x/y coordinates as propertioes and create custom signals that contain the x/y values.
And there are even more possibilities...
-
The last option is probably the cleanest, though you could also just make the whole grid of buttons into a class that has such a clicked(int, int) signal instead, and use an internal QSignalMapper and some basic math to map a single ID to an (int, int) coordinate.
[small]You're not trying to make a calendar out of it, are you?[/small]