PDA

View Full Version : QTableView column header is invisible



grsandeep85
20th October 2009, 11:45
Hi All,

I have made a QTableView with 200 rows and 4 columns.. but the column header are invisible and here is my code snippet.

toolform.cpp


ToolForm::ToolForm(QDialog *parent, Qt::WindowFlags f)
: QDialog( parent, f)
{
setupUi(this);
setupModel();
setupViews();
init();
}

ToolForm::~ToolForm()
{
}

void ToolForm::init()
{

}
void ToolForm::setupModel()
{
model = new QStandardItemModel(200, 4, this);
model->setHeaderData(0, Qt::Horizontal, tr("NUMBER"));
model->setHeaderData(1, Qt::Horizontal, tr("DIAMETER"));
model->setHeaderData(2, Qt::Horizontal, tr("LENGTH"));
model->setHeaderData(3, Qt::Horizontal, tr("UNITS"));
}

void ToolForm::setupViews()
{
QTableView *tooltableView = new QTableView;
tooltableView->setModel(model);
QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
tooltableView->setSelectionModel(selectionModel);
}



toolform.h



#ifndef TOOLFORM_H
#define TOOLFORM_H

#include <QVariant>
#include <QDialog>

#include "ui_toolform.h"

class QAbstractItemModel;
class QItemSelectionModel;


class ToolForm : public QDialog, private Ui::ToolForm
{
Q_OBJECT

public:
ToolForm( QDialog* parent = 0, Qt::WindowFlags f = Qt::FramelessWindowHint);
~ToolForm();

private:

void setupModel();
void setupViews();
void init();

QAbstractItemModel *model;
QItemSelectionModel *selectionModel;
};

#endif // TOOLFORM_H


How to resolve this issue.:)

spirit
20th October 2009, 11:50
try this:


void ToolForm::setupViews()
{
QTableView *tooltableView = new QTableView;
tooltableView->setModel(model);
QItemSelectionModel *selectionModel = new QItemSelectionModel(model);
tooltableView->setSelectionModel(selectionModel);
toolrableView->show();
}

grsandeep85
20th October 2009, 12:04
Hi Spirit,
Thanks for the reply its working fine.