[Qt-interest] Required columns of a QTableView
Vladimir Barbarosh
vladimir.barbarosh at gmail.com
Sat Oct 9 21:49:53 CEST 2010
On Thu, Oct 7, 2010 at 11:40 AM, Harry Sfougaris <hsfougaris at gmail.com> wrote:
> I am trying to show visually which fields are required in a form.
> For QLineEdit fields, I am using setProperty("required", true) and have an appropriate stylesheet that displays the field with a yellow background.
> But I also have a QTableView on the form, and some of the columns are required, and would like to do something similar.
> What would be the best way to do that? Is there a way to set a property on column of a QTableView?
> I was looking for something like setColumnProperty(...) (the way there is setColumnHidden) but there doesn't seem to be anything similar.
>
> Thanks,
> Harry Sfougaris
Take a look at
QAbstractItemModel::setHeaderData()
http://doc.qt.nokia.com/4.7/qabstractitemmodel.html#setHeaderData
enum Qt::ItemDataRole
http://doc.qt.nokia.com/4.7/qt.html#ItemDataRole-enum
QHeaderView Appearance
http://doc.qt.nokia.com/4.7/qheaderview.html#appearance
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include <QtGui/QApplication>
#include <QtGui/QStandardItemModel>
#include <QtGui/QTableView>
int
main(int argc, char **argv)
{
QApplication app(argc, argv);
QStandardItemModel model;
model.setRowCount(5);
model.setColumnCount(5);
model.setHeaderData(0, Qt::Horizontal, "Does this helps?");
model.setHeaderData(0, Qt::Horizontal, Qt::red, Qt::BackgroundRole);
QTableView view;
view.setModel(&model);
view.show();
return app.exec();
}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Does it helps?
More information about the Qt-interest-old
mailing list