tescrin
5th July 2012, 18:31
So I've been looking at the documentation as I clean up some code and with QActions you can (and I have) stored data so you can simply grab or update data (i.e. the data is abstracted from the action's text)
All the solutions I've seen with QPushButtons (and have implemented this far) involve deriving the data from the text of the button. This seems like a backwards way to do it as the button, even if it's an inefficient use of space, SHOULD store the data rather than the code "derive" the data from the text of the button at all times. It seems hokey to go through this process of converting a button's text to data and it doesn't feel right that the "data" isn't abstracted from the button.
Basically my question is if there's another way of doing this without subclassing the button to add a data member. Like the QAction is there a setData() member I might be missing?
P.S.
For instance: Let's say you have an EE button on a calculator. You could store the "E" in the button, but you wouldn't want to use it's text of "EE." I solved this problem by simply adding a function that deals with it called by the clicked() signal; but being able to derive any button's data with a single function cleans up the entire code by a mile. This and other similar instances are why I'm asking.
All the solutions I've seen with QPushButtons (and have implemented this far) involve deriving the data from the text of the button. This seems like a backwards way to do it as the button, even if it's an inefficient use of space, SHOULD store the data rather than the code "derive" the data from the text of the button at all times. It seems hokey to go through this process of converting a button's text to data and it doesn't feel right that the "data" isn't abstracted from the button.
Basically my question is if there's another way of doing this without subclassing the button to add a data member. Like the QAction is there a setData() member I might be missing?
P.S.
For instance: Let's say you have an EE button on a calculator. You could store the "E" in the button, but you wouldn't want to use it's text of "EE." I solved this problem by simply adding a function that deals with it called by the clicked() signal; but being able to derive any button's data with a single function cleans up the entire code by a mile. This and other similar instances are why I'm asking.