Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 1

Qt-interest Archive, August 2007
Real number notation in QTableView


Message 1 in thread

Hi,

How can I change Real number notation in QTableView.
By default it converts big real number to scientific format (like 1.02e+8).
But fixed format is needed (102 000 000).

Regards,
David

--
 [ signature omitted ] 

Message 2 in thread

Is the only way is custom delegate implementataion?

----- Original Message ----- 
From: "David Osipyan" <David_Osipyan@xxxxxxxxxxx>
To: "qt" <qt-interest@xxxxxxxxxxxxx>
Sent: Wednesday, August 01, 2007 2:32 PM
Subject: Real number notation in QTableView


> Hi,
>
> How can I change Real number notation in QTableView.
> By default it converts big real number to scientific format (like 
> 1.02e+8).
> But fixed format is needed (102 000 000).
>
> Regards,
> David
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with 
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
> 

--
 [ signature omitted ] 

Message 3 in thread

Yes, i think so. (which is a pity, as this is a bit clumsy)

Its the same with localized date formats. It would be good to have a
template for delegates to easily modify the display format.

Cheers,
Peter

> -----Original Message-----
> From: David Osipyan [mailto:David_Osipyan@xxxxxxxxxxx]
> Sent: Wednesday, August 01, 2007 11:46 AM
> To: David Osipyan; qt
> Subject: Re: Real number notation in QTableView
> 
> Is the only way is custom delegate implementataion?
> 
> > How can I change Real number notation in QTableView.
> > By default it converts big real number to scientific format (like
> > 1.02e+8).
> > But fixed format is needed (102 000 000).

--
 [ signature omitted ] 

Message 4 in thread

Am Donnerstag, den 02.08.2007, 12:40 +0200 schrieb Peter Prade:
> Yes, i think so. (which is a pity, as this is a bit clumsy)
> 
> Its the same with localized date formats. It would be good to have a
> template for delegates to easily modify the display format.

What about returning QString::number() in your data() method?

#include <QtGui>
class MyModel : public QAbstractTableModel
{
public:
	MyModel ( const QList<qreal> &input, QObject * parent = 0 ) : QAbstractTableModel(parent)
	{
		m_reals = input;
	}	
	QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const 
	{
		if (role == Qt::DisplayRole || role == Qt::EditRole )
		{
			if (index.column() == 0)
				return m_reals.at(index.row() );
			else
			{
				int res = m_reals.at(index.row());
				return QString::number(res);
			}
		}
		return QVariant();
	}
	int rowCount( const QModelIndex & )const
	{
		return m_reals.count();
	}
	int columnCount( const QModelIndex & ) const 
	{
		return 2;
	}
	Qt::ItemFlags flags ( const QModelIndex & index ) const   
	{
		if (index.column() == 1)
			return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
		else
			return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
	}
	bool setData ( const QModelIndex & index, const QVariant & value, int role = Qt::EditRole )  
	{
		m_reals.replace(index.row(), value.toInt());
		return true;
	}
private:
	QList<qreal> m_reals;
};

int main(int argc, char *argv[])
{
	QApplication app(argc, argv);
	QList<qreal>  startReals;
	startReals << 1020000000. << 1000.<< 100.; 
	MyModel *myMod = new MyModel(startReals );
	
	QTableView *tv = new QTableView;
	tv->setModel(myMod);
	
	tv->show();
	
	return app.exec();
}

\Ralf

--
 [ signature omitted ] 

Message 5 in thread

Ralf Neubersch wrote:
> Am Donnerstag, den 02.08.2007, 12:40 +0200 schrieb Peter Prade:
> > Yes, i think so. (which is a pity, as this is a bit clumsy)
> >
> > Its the same with localized date formats. It would be good to have a
> > template for delegates to easily modify the display format.
> 
> What about returning QString::number() in your data() method?

That works, but it's a hack, as it destroys sorting.

Cheers,
Peter


--
 [ signature omitted ] 

Message 6 in thread

Please reply to the list, not to me in private.

Ralf Neubersch wrote:
> Am Donnerstag, den 02.08.2007, 14:06 +0200 schrieb Peter Prade:
> > Ralf Neubersch wrote:
> > > Am Donnerstag, den 02.08.2007, 12:40 +0200 schrieb Peter Prade:
> > > > Yes, i think so. (which is a pity, as this is a bit clumsy)
> > > >
> > > > Its the same with localized date formats. It would be good to
have a
> > > > template for delegates to easily modify the display format.
> > >
> > > What about returning QString::number() in your data() method?
> >
> > That works, but it's a hack, as it destroys sorting.
> 
> Well then, use a QStandardItemModel and its sortRole() mechanism.....
> 
> \Ralf

Another clumsy workaround to be able to use a hack?

What i'd like to be able to do is to set a date format that should be
used to paint dates - either in the table view or even globally and not
transfer all my data into string format so that i can choose the format.

Ranting,
Peter

--
 [ signature omitted ] 

Message 7 in thread

Am Donnerstag, den 02.08.2007, 16:31 +0200 schrieb Peter Prade:
> Please reply to the list, not to me in private.
> 

Sorry, but evolution has the "answer to list" function well hidden in
the menus ;-)

> Another clumsy workaround to be able to use a hack?
> 
> What i'd like to be able to do is to set a date format that should be
> used to paint dates - either in the table view or even globally and not
> transfer all my data into string format so that i can choose the format.

In other words: you want Qt to do the work, not yourself. While this is understandable and I would also like the ability to set output formats, 
this is something Qt just doesn't have at the moment.

So you might call it a "hack", I'd tend to call it "workaround". And converting the data into strings etc. 
will presumably exactly be what will happen behind the scenes, if Qt one day offers such format handling.

These are your options:

a) make a suggestion to Trolltech to support what you want. 
a+) write the code yourself and offer it to Trolltech (no, I did *not* say "give")
b) write a workaround
c) continue ranting......

\Ralf

--
 [ signature omitted ] 

Message 8 in thread

Ralf Neubersch wrote:
> In other words: you want Qt to do the work, not yourself. While this
is
> understandable and I would also like the ability to set output
formats,
> this is something Qt just doesn't have at the moment.

You might have missed that i'm not the OP of the thread, i'm just
ranting while i basically say, "yes the only way is a custom delegate
implementation".

> So you might call it a "hack", I'd tend to call it "workaround". And
> converting the data into strings etc.
> will presumably exactly be what will happen behind the scenes, if Qt
one
> day offers such format handling.

I don't agree here, it would be easy for Qt to offer other presentation
of e.g. dates than in ISO-Format.

> These are your options:
> 
> a) make a suggestion to Trolltech to support what you want.
> a+) write the code yourself and offer it to Trolltech (no, I did *not*
say
> "give")
> b) write a workaround
> c) continue ranting......

agreed, it would be a good idea to enter a suggestion into the
tasktracker of Trolltech. thats what i just did.

a "format role" would possibly a good solution for this kind of problem.

Cheers,
Peter

--
 [ signature omitted ]