QListView only displaying last item
Hi everyone,
I am totally new to QT(Jambi) and tried to create a simple application with a QListView
that should contain some numbers. Unfortunately only the last number is displayed.
What am I doing wrong?
Here is the code of my two classes:
Code:
import java.util.ArrayList;
import java.util.List;
import com.
trolltech.
qt.
gui.
QWidget;
{
Ui_MainWindow ui = new Ui_MainWindow();
public static void main(String[] args)
{
ListBox gnah = new ListBox();
gnah.show();
}
public ListBox()
{
ui.setupUi(this);
initialize();
}
{
super(parent);
ui.setupUi(this);
initialize();
}
private void initialize()
{
List<Integer> data = new ArrayList<Integer>();
data.add(42);
data.add(666);
data.add(1337);
ListBoxModel model = new ListBoxModel(data);
this.ui.listView.setModel(model);
}
}
Code:
import java.util.List;
import com.trolltech.qt.core.Qt.ItemDataRole;
{
private List<Integer> data;
public ListBoxModel(List<Integer> data)
{
this.data = data;
}
@Override
{
if(arg1 == ItemDataRole.DisplayRole)
{
return data.get(arg0.row());
}
else
{
return null;
}
}
@Override
{
return data.size();
}
}
Re: QListView only displaying last item
I don't know how it looks in Java, but rowCount() and data() are const methods, maybe that's something you forgot about. Are your implementations being called at all?