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:
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);
}
}
import java.util.ArrayList;
import java.util.List;
import com.trolltech.qt.gui.QApplication;
import com.trolltech.qt.gui.QMainWindow;
import com.trolltech.qt.gui.QWidget;
public class ListBox extends QMainWindow
{
Ui_MainWindow ui = new Ui_MainWindow();
public static void main(String[] args)
{
QApplication.initialize(args);
ListBox gnah = new ListBox();
gnah.show();
QApplication.exec();
}
public ListBox()
{
ui.setupUi(this);
initialize();
}
public ListBox(QWidget parent)
{
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);
}
}
To copy to clipboard, switch view to plain text mode
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();
}
}
import java.util.List;
import com.trolltech.qt.core.QAbstractListModel;
import com.trolltech.qt.core.QModelIndex;
import com.trolltech.qt.core.Qt.ItemDataRole;
public class ListBoxModel extends QAbstractListModel
{
private List<Integer> data;
public ListBoxModel(List<Integer> data)
{
this.data = data;
}
@Override
public Object data(QModelIndex arg0, int arg1)
{
if(arg1 == ItemDataRole.DisplayRole)
{
return data.get(arg0.row());
}
else
{
return null;
}
}
@Override
public int rowCount(QModelIndex arg0)
{
return data.size();
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks