Hi,

i'm having some troubles trying to use a QCompleter with a custom Model.

The problem is that if I use the setCompletionColumn(int column) function, the 
popup don't scroll down with the down key (but works with the up key). If I 
change the position of the completion column to 0 and comment the 
setCompletionColumn() the model works well.

This is the importan part:

nombreClientesCompleter = new QCompleter();
                clientesVectorModel = new ClientesVectorModel(Cliente.getAll());
        nombreClientesCompleter.setModel(clientesVectorModel);
        
nombreClientesCompleter.setCaseSensitivity(CaseSensitivity.CaseInsensitive);
        nombreClientesCompleter.setCompletionColumn(1);
        ui.razonSocialLineEdit.setCompleter(nombreClientesCompleter);
        nombreClientesCompleter.activatedIndex.connect(this, 
"completarCliente(QModelIndex)");

This is the imp. of my custom model:

package com.nettrace.models;

import java.util.Collections;
import java.util.Vector;

import com.trolltech.qt.core.QModelIndex;
import com.trolltech.qt.core.Qt.ItemDataRole;
import com.trolltech.qt.core.Qt.Orientation;
import com.trolltech.qt.gui.QAbstractTableModel;

public class ClientesVectorModel extends QAbstractTableModel {
        
        public Vector<Cliente> clientes= new Vector<Cliente>();
        
        public ClientesVectorModel(Vector<Cliente> clientes) {
                super();
                this.clientes.addAll(clientes);
                Collections.sort(this.clientes);
        }
        
        @Override
        public int columnCount(QModelIndex arg0) {
                return 9;
        }

        @Override
        public Object data(QModelIndex index, int role) {
                String data= null;
                if(role == ItemDataRole.DisplayRole || role == 
ItemDataRole.EditRole){
                        if(index.column()==0){
                                data = 
String.valueOf(clientes.elementAt(index.row()).getId()); 
                        }
                        else if (index.column() == 1){
                                
                                data = 
clientes.elementAt(index.row()).getRazonSocial();
                        }
                        else if (index.column() == 2){
                                data = 
clientes.elementAt(index.row()).getEstado();

                        }
                        else if (index.column() == 3){
                                data = 
clientes.elementAt(index.row()).getCiudad();

                        }
                        else if (index.column() == 4){
                                data = 
clientes.elementAt(index.row()).getColonia();

                        }
                        else if (index.column() == 5){
                                data = clientes.elementAt(index.row()).getCp();

                        }
                        else if (index.column() == 6){
                                data = 
clientes.elementAt(index.row()).getDireccion();
                        }
                        else if (index.column() == 7){
                                data = clientes.elementAt(index.row()).getRfc();
                        }
                        else if (index.column() == 8){
                                data = 
clientes.elementAt(index.row()).getTelefono();
                        }       
                }
                return data;

        }
        
        public Object headerData(int section, Orientation orientation, int 
role) {
                System.out.println("ClientesVectorModel.headerData()");
                if(orientation == Orientation.Horizontal){
                        if(role == ItemDataRole.DisplayRole){
                                if(section == 1){
                                        return "Razon Soc.";
                                }
                                else if(section == 2){
                                        return "Estado";
                                }
                                else if(section == 3){
                                        return "Ciudad";
                                }
                                else if(section == 4){
                                        return "Colonia";
                                }
                                else if(section == 5){
                                        return "Cp";
                                }
                                else if(section == 6){
                                        return "Direccion";
                                }
                                else if(section == 7){
                                        return "RFC";
                                }
                                else if(section == 8){
                                        return "Telefono";
                                }
                        }
                }
                return super.headerData(section, orientation, role);
        } 

        @Override
        public int rowCount(QModelIndex parent) {
                return clientes.size();
        }

}



_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest

Reply via email to