PDA

View Full Version : Row number in a QSqlQueryModel



fnmblot
15th May 2008, 18:38
Is there any way to remove the row number in a QSqlQueryModel? I tried:

tableViewModel->removeColumn(0);
but that removes my first column of data.

The reason I need this removed is the database missing the number 13 and seeing a row number next to the UID gets a little confusing. (I am a little superstitous.)

jpn
15th May 2008, 18:45
You mean the vertical header?

tableView->verticalHeader()->hide();

fnmblot
15th May 2008, 19:29
well, I am getting errors compiling when I try that method.

src/tableVCS.cpp:22: error: invalid use of undefined type struct QHeaderView
/usr/include/QtGui/qtableview.h:55: error: forward declaration of struct QHeaderView
make[1]: *** [build/tableVCS.o] Error 1

Here is the code for the table:

#include "tableVCS.h"
#include <QtSql>
//
tableVCSDlg::tableVCSDlg( QWidget * parent, Qt::WFlags f)
: QDialog(parent, f)
{
tableVCSUi.setupUi(this);

QSqlQueryModel *tableViewModel = new QSqlQueryModel;
tableViewModel->setQuery("SELECT piece_name, nn, short_instrum FROM main WHERE nn !='0' ORDER BY nn");

tableViewModel->setHeaderData(0, Qt::Horizontal, "Piece Name");
tableViewModel->setHeaderData(1, Qt::Horizontal, "NN");
tableViewModel->setHeaderData(2, Qt::Horizontal, "Instrumentation");


tableVCSUi.tableView->setModel(tableViewModel);
tableVCSUi.tableView->resizeColumnsToContents();
tableVCSUi.tableView->verticalHeader()->hide();
}

tableVCSDlg::~tableVCSDlg()
{}
//End tableVCS.cpp

jpn
15th May 2008, 19:36
#include <QHeaderView>

fnmblot
15th May 2008, 19:43
That is why you are a Guru and I am just a wee Novice. Thanks a million jpn! It worked like a charm.