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



  • Sorry, I absolutly do not get the question. What do you want to achieve?

    A Gameboard (like a chess board) with buttons and if you click one, get the field coordinate (like A8)?



  • yeah! ^^

    but the field coordinate its (int, int)

    I think a board is made with several buttons but maybe there is another way

    thanks for answer
    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]



  • ok thanks

    i will implement their ideas to see what I find

    not a calendar btw ^^

    really thanks

    greetings


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.