PDA

View Full Version : Regarding alignment in QTable



joseph
5th December 2006, 07:16
Hai guys,

Qt Version : Qt 3.3.4
Problem : Regarding alignment in QTable

I am facing a porblem ., I need to align the cell_data in QTable to Left/ Right as per certain conditons.
One of my friends get a reply from forum that " you can set the alignment, setting all alignment of the text contents of the tableItems.. ". But i didnot see any function in the Qt Assistant like this instead of " int QTableItem::alignment () const [virtual] "


My need is something like this QTableItem::setAlignment( Alignment ) .

Please help me if you can

Thanks

wysota
5th December 2006, 07:21
You have to reimplement alignment() in a subclass of QTableItem and return proper alignment you wish the item to have, for example:


int MyTableItem::alignment(){
if(text()[0]=='X') return Qt::AlignLeft; // align left for items beginning with "X"
return Qt::AlignRight; // align right for others
}

joseph
5th December 2006, 10:34
I have implemented like as below ... but not working the alignment to LEFT


class MyTableItem : public QTableItem
{

public:
MyTableItem( QTable * table, EditType editType, const QString & text )
:QTableItem ( table, editType, text )
{

}
~MyTableItem()
{
/*NOOP*/
}
int alignment()
{
return Qt::AlignLeft; //or Qt::AlignRight;

}

};

Then inside my MyMainWindow Class.... as follows


------
-----
void MyMainWindow :: refreshTable()
{
----
myTable->setItem( row , col, new MyTableItem( myTable , QTableItem::Never, TextInCell );
---
}

I have debugged the code , the control comes in alignment() of MyTableItem...

please lead me to a right way if i am wrong..

Thank you

wysota
5th December 2006, 10:51
It should be "int alignment() const" and not "int alignment()".

joseph
5th December 2006, 11:35
:D
Thank you so much ..It's working fine
I use this opertunity to thank you onbehalf of our team.