qt-interest@trolltech.com
[Top] [All Lists]

Re: Changing Alignment of QTableItem with Localized Number format

Subject: Re: Changing Alignment of QTableItem with Localized Number format
From: Bulent Oktem
Date: Sun, 24 Oct 2004 15:49:55 +0300
> Subclassing is an easy and standard operation when using object-oriented
> libraries. Why do you feel it's not a good solution?
>
Well it is already in my code and I didnt want to go and change it everywhere.
> Now the question is what happens with toInt() and toDouble(). According
> to the documentation these functions are making use of the locale:
>       http://doc.trolltech.com/3.3/qstring.html#toInt
>       http://doc.trolltech.com/3.3/qstring.html#toDouble
Here is code where put two numbers into QTable first number, second formatted 
with Local

table_x->setText( 1, 1, QString("%L1").arg(num1));
table_x->setText( 1, 2, QString::number(num2));

they are aligned differently :).
> Maybe this is not working properly in your case for some reason. What
> version of Qt is this? On which platform? What is your locale? What are
> the strings that fail to align properly?
QT 3.3.3 with Suse Linux 9.1, Local is US but shouldnt matter cause I am using 
%L1 to format it anyway.

Thnx,
Bulent



On Sunday 24 October 2004 15:13, Dimitri wrote:
> Hi,
>
> > I am trying to create a QTable with numbers aligned to right and text to
> > left. This sound the way QTableItem works, as long as you dont try to
> > format the numbers with Localization, thus commas and periods, then
> > QTableItem recognizes the entry as string and left aligns. Is there any
> > easy way without subclassingway either to make
> >     QTableItem format numbers with locals or,
> >     to make QTableItem understand that localized numbers are not strings?
>
> Subclassing is an easy and standard operation when using object-oriented
> libraries. Why do you feel it's not a good solution?
>
> Anyway, the source code looks like:
>       int QTableItem::alignment() const
>       {
>           bool num;
>           bool ok1 = FALSE, ok2 = FALSE;
>           (void)text().toInt( &ok1 );
>           if ( !ok1 )
>               (void)text().toDouble( &ok2 );
>           num = ok1 || ok2;
>           return ( num ? AlignRight : AlignLeft ) | AlignVCenter;
> which is consistent with the documentation.
>
> Now the question is what happens with toInt() and toDouble(). According
> to the documentation these functions are making use of the locale:
>       http://doc.trolltech.com/3.3/qstring.html#toInt
>       http://doc.trolltech.com/3.3/qstring.html#toDouble
> Maybe this is not working properly in your case for some reason. What
> version of Qt is this? On which platform? What is your locale? What are
> the strings that fail to align properly?
>
> --
> Dimitri
>
> --
> List archive and information: http://lists.trolltech.com/qt-interest/

--
List archive and information: http://lists.trolltech.com/qt-interest/

<Prev in Thread] Current Thread [Next in Thread>