Vincent Lebreil wrote:
> Hi,
>
> I'm trying to display a background color for all items of my model.
> I've tried to return a QColor in my data method for BackgroundRole. But
> this color is only displayed if the mouse is over one row of my view.
> This color is not displayed for all the rows of my view.
> I don't understand why, cause if I do the same thing but with
> DecorationRole, it works great (ie all the rows of my view have this
> decoration).
>
> Thanks for your help
Hi Vincent,
In the following example, I set the displayrole to red and it
consistently produces red cells. Are you doing anyting differently?
import java.util.*;
import com.trolltech.qt.gui.*;
import com.trolltech.qt.core.*;
public class TableModelMyFile extends QAbstractTableModel {
ArrayList<String> myFiles;
public TableModelMyFile(ArrayList<String> myFiles) {
this.myFiles = myFiles;
}
public int columnCount(QModelIndex i) { return 5; }
public int rowCount(QModelIndex i) { return myFiles.size(); }
public Object data(final QModelIndex index, int role) {
switch (role) {
case Qt.ItemDataRole.DisplayRole:
return myFiles.get(index.row()) + ":" + index.column();
case Qt.ItemDataRole.BackgroundRole:
return QColor.red;
default:
break;
}
return null;
}
public void doStuff() {
beginInsertRows(null, 3, 3);
myFiles.add("Four");
endInsertRows();
}
public static void main(String args[]) {
QApplication.initialize(args);
QTableView view = new QTableView();
ArrayList<String> list = new ArrayList<String>();
list.add("One");
list.add("Two");
list.add("Three");
final TableModelMyFile model = new TableModelMyFile(list);
view.setModel(model);
view.show();
QApplication.invokeLater(3000, new Runnable() {
public void run() {
model.doStuff();
}
});
QApplication.exec();
}
}
_______________________________________________
Qt-jambi-interest mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-jambi-interest