PDA

View Full Version : How to QTableWidget default values on insertion?



RawArkanis
20th April 2010, 03:29
Hi all!

I'm trying to make some tables where some fields have a default value.
When a new record is inserted into these fields, they should be filled with their default values.

I am having difficulty doing that. I have several different tables, all inherits some methods of a base baseclass (modified QTableWidget), such as keyEvents.
In these events I use the function for inserting rows. So I could not just put the defaults after.

Is there any method that can be re-implemented to run every time a new row is inserted? Or should I do otherwise?
I thinked about... I can make a virtual method in the baseclass and call it after the row insertion, then re-implement in the child class. Is this a better way?

Sorry, for my bad english!

If needed, I can post the code here.

Thx!

Lykurg
20th April 2010, 08:02
As I understand you, you have a base class with a function that creates a new row with several items.
So why do you not just put the desired values there? Make a member variable where you store the default values (this variable is defined by each subclass) and use these values while create your new row.
class BaseClass{
QList<int> defaultValues;
void createRow() {
// use defaultValues
}
};

class Child : public BaseClass
{
public:
BaseClass() {
defaultValues = //...
}
}


Of course a private member variable with a proper setter function is nicer...