PDA

View Full Version : Row and Coloum Position



rahulgogoi
30th May 2011, 11:14
hello friends

Actually i have created an Array of buttons in 6 X 7 matrix..now if on each click of the button i want to know the positons of row and colums of that particular buttons that i have clicked than how it can be done…please suggest me..

regards
Rahul

SixDegrees
30th May 2011, 12:25
Ask whatever QLayout you used.

Or embed the information in each button.

Or calculate it based on the pixel size of the array and what's known about the geometry of the buttons.

yeye_olive
30th May 2011, 15:17
When you connect several signals to the same slot and you need to know in the slot which signal was emitted, you can use QSignalMapper. Basically it allows you to add an argument to the slot, of type int, QString, QWidget* or QObject*) to help you identify the emitter.

In your case I can suggest two options:

- embed the information in each button like SixDegrees suggested (e.g. by deriving QPushButton and declaring and initializing appropriate fields) and map each button to a pointer to itself (QWidget*) in the QSignalMapper; that way you get back the pointer in the slot and can read the information from the object.

- do not bother deriving QPushButton and map each button to an integer identifying it; for example, if i, j are the coordinates of a button (i in 0..5 and j in 0..6), map the button to the integer i * 7 + j; you can then use / and % to recover i and j from the integer in the slot.