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

Qt-jambi-interest Archive, July 2007
QTableView


Message 1 in thread

Hello,

I filled QTableView with java.sql.resultset

For my line resultset.getDouble (“montFacture”) I do not arrive has to 
post correctly more than 6 characters.

Example:

while ( resultset.next ( ) )
remplirQTableView
( qstandarditemmodel, resultset.getDouble ( "montFacture" ) ) ;

post 5,55496e+06 in QTableView.

But one:

while ( resultset.next ( ) )
System.out.println ( resultset.getDouble ( "montFacture" ) ) ;

correctly post my 5554958.15 in the terminal.

Suggestion?

A+,

Claude.




Message 2 in thread

claude.faath wrote:
> Hello,
> 
> I filled QTableView with java.sql.resultset
> 
> For my line resultset.getDouble (“montFacture”) I do not arrive has to 
> post correctly more than 6 characters.
> 
> Example:
> 
> while ( resultset.next ( ) )
> remplirQTableView
> ( qstandarditemmodel, resultset.getDouble ( "montFacture" ) ) ;
> 
> post 5,55496e+06 in QTableView.
> 
> But one:
> 
> while ( resultset.next ( ) )
> System.out.println ( resultset.getDouble ( "montFacture" ) ) ;
> 
> correctly post my 5554958.15 in the terminal.
> 
> Suggestion?

Hi Claude,

This is simply how the view displays floating point values. They are 
displayed in scientific notation. This is only the visual aspect though. 
The actual content is unchanged.

If you want to draw the text differently this is done by subclassing a 
QItemDelegate. I've attached a small example that illustrates how this 
can be done.


import java.awt.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import com.trolltech.qt.*;
import com.trolltech.qt.core.*;
import com.trolltech.qt.gui.*;

public class Test
{
    public static void main(String args[]) {
	QApplication.initialize(args);

        QTableView view = new QTableView();

        final QStandardItemModel model = new QStandardItemModel();
        view.setModel(model);

        model.insertRows(0, 10);
        model.insertColumns(0, 10);
        model.setData(1, 1, 5.123456789);

        view.setItemDelegate(new QItemDelegate() {
            public void paint(QPainter painter, QStyleOptionViewItem option, QModelIndex index) {
                Object value = model.data(index);
                if (value != null) {
                    painter.drawText(option.rect(),
                                     Qt.AlignmentFlag.AlignCenter.value(),
                                     model.data(index).toString());
                } else {
                    super.paint(painter, option, index);
                }
            }
            });

        view.show();

        QApplication.exec();
    }
}