Well, to be honest, I don't think you have really tried it, because it works fine. It is more likely you use wrong code. But without seeing anything.... The simple setFont solution with a custom delegate works perfect:
#include <QtGui>
class delegate : public QStyledItemDelegate
{
public:
delegate
(QObject* parent
= 0) : QStyledItemDelegate
(parent
) {}
void paint
(QPainter* painter,
const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
QStyledItemDelegate::paint(painter, option, index);
}
};
int main(int argc, char* argv[])
{
list << "a" << "b" << "c";
w.
setFont(QFont("Courier",
30));
delegate d;
w.setItemDelegate(&d);
w.addItems(list);
w.show();
lv.
setFont(QFont("Courier",
30));
lv.setItemDelegate(&d);
m.setStringList(list);
lv.setModel(&m);
lv.show();
return a.exec();
}
#include <QtGui>
class delegate : public QStyledItemDelegate
{
public:
delegate(QObject* parent = 0) : QStyledItemDelegate(parent)
{}
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const
{
QStyledItemDelegate::paint(painter, option, index);
}
};
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
QStringList list;
list << "a" << "b" << "c";
QListWidget w;
w.setFont(QFont("Courier", 30));
delegate d;
w.setItemDelegate(&d);
w.addItems(list);
w.show();
QListView lv;
lv.setFont(QFont("Courier", 30));
lv.setItemDelegate(&d);
QStringListModel m;
m.setStringList(list);
lv.setModel(&m);
lv.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks