After try and error in this morning, now the tableview can successfully display in the Tab.
But application output section came some messages :
...going on...
QModelIndex(0,0,0x0,QAbstractTableModel(0xb4f070) )
QModelIndex(0,0,0x0,QAbstractTableModel(0xb4f070) )
QModelIndex(0,0,0x0,QAbstractTableModel(0xb4f070) )
QModelIndex(0,0,0x0,QAbstractTableModel(0xb4f070) )
QModelIndex(0,0,0x0,QAbstractTableModel(0xb4f070) )
QModelIndex(0,0,0x0,QAbstractTableModel(0xb4f070) )
...going on...
To copy to clipboard, switch view to plain text mode
Here is the code. using Qt Creator IDE.
I made several tabs and try to place a table in the Tab named "TestTbTab"
In m_TabDialog.cpp, comment part is using TableWidget and can successfully build.
and the rest of the part shows my TableView usage.
m_TabDialog.h
#ifndef M_TABDIALOG_H
#define M_TABDIALOG_H
#include<QtGui>
#include<QDialog>
#include<QTableView>
#include<QTableWidget>
#include<QTableWidgetItem>
#include<QGridLayout>
#include"TableModel.h"
QT_BEGIN_NAMESPACE
QT_END_NAMESPACE
// class m a i n t a b
{
Q_OBJECT
public:
};
// class D E B U G T A B
{
Q_OBJECT
public:
};
// class T e s t T a b
{
Q_OBJECT
public:
};
//class T e s t T b T a b
{
public:
private:
TableModel *model;
};
//class T a b D i a l o g
{
Q_OBJECT
public:
private:
};
#endif // M_TABDIALOG_H
#ifndef M_TABDIALOG_H
#define M_TABDIALOG_H
#include<QtGui>
#include<QDialog>
#include<QTableView>
#include<QTableWidget>
#include<QTableWidgetItem>
#include<QGridLayout>
#include"TableModel.h"
QT_BEGIN_NAMESPACE
class QDialogButtonBox;
class QFileInfo;
class QTabWidget;
QT_END_NAMESPACE
// class m a i n t a b
class MainTab : public QWidget
{
Q_OBJECT
public:
MainTab(const QFileInfo &fileInfo, QWidget *parent = 0);
};
// class D E B U G T A B
class DebugTab : public QWidget
{
Q_OBJECT
public:
DebugTab(const QFileInfo &fileInfo, QWidget *parent =0);
};
// class T e s t T a b
class TestTab : public QWidget
{
Q_OBJECT
public:
TestTab(const QFileInfo &fileInfo, QWidget *parent = 0);
};
//class T e s t T b T a b
class TestTbTab : public QWidget
{
public:
TestTbTab(const QFileInfo &fileInfo, QWidget *parent = 0);
QWidget *tab;
private:
QGridLayout *grid_layout;
TableModel *model;
QTableView *view;
};
//class T a b D i a l o g
class TabDialog : public QDialog
{
Q_OBJECT
public:
TabDialog(const QString &fileName, QWidget *parent = 0);
private:
QTabWidget *tabWidget;
QDialogButtonBox *btnBox;
QWidget tab;
};
#endif // M_TABDIALOG_H
To copy to clipboard, switch view to plain text mode
m_TabDialog.cpp (for focusing on problem, pass other Tabs)
#include"m_TabDialog.h"
{
tabWidget->addTab(new MainTab(fileInfo),tr("Main"));
tabWidget->addTab(new DebugTab(fileInfo),tr("Debug"));
tabWidget->addTab(new TestTab(fileInfo),tr("Test"));
tabWidget->addTab(new TestTbTab(fileInfo),tr("testTable"));
connect(btnBox, SIGNAL(accepted()),this,SLOT(accept()));
connect(btnBox, SIGNAL(accepted()),this,SLOT(reject()));
mainLayout->addWidget(tabWidget);
mainLayout->addWidget(btnBox);
setLayout(mainLayout);
setWindowTitle(tr("test yaya"));
}
/*
TestTbTab::TestTbTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent)
{
QTableWidget *tableWidget = new QTableWidget;
tableWidget->setRowCount(5);
tableWidget->setColumnCount(5);
tableWidget->setWindowTitle(QObject::tr("test tablewidget"));
tableWidget->maximumSize();
QStringList m_header;
m_header<<"item1"<<"item2";
tableWidget->setHorizontalHeaderLabels(m_header);
tableWidget->setItem(0,0,new QTableWidgetItem("Jan"));
tableWidget->setItem(1,0,new QTableWidgetItem("Feb"));
tableWidget->setItem(2,0,new QTableWidgetItem("Feb"));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(tableWidget);
setLayout(layout);
}*/
{
model = new TableModel(this);
view->setModel(model);
view
->setWindowTitle
(QObject::tr("test designed Model"));
grid_layout->addWidget(view);
setLayout(grid_layout);
}
#include"m_TabDialog.h"
TabDialog::TabDialog(const QString &fileName, QWidget *parent) : QDialog(parent)
{
QFileInfo fileInfo(fileName);
tabWidget = new QTabWidget;
tabWidget->addTab(new MainTab(fileInfo),tr("Main"));
tabWidget->addTab(new DebugTab(fileInfo),tr("Debug"));
tabWidget->addTab(new TestTab(fileInfo),tr("Test"));
tabWidget->addTab(new TestTbTab(fileInfo),tr("testTable"));
btnBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
connect(btnBox, SIGNAL(accepted()),this,SLOT(accept()));
connect(btnBox, SIGNAL(accepted()),this,SLOT(reject()));
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addWidget(tabWidget);
mainLayout->addWidget(btnBox);
setLayout(mainLayout);
setWindowTitle(tr("test yaya"));
}
/*
TestTbTab::TestTbTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent)
{
QTableWidget *tableWidget = new QTableWidget;
tableWidget->setRowCount(5);
tableWidget->setColumnCount(5);
tableWidget->setWindowTitle(QObject::tr("test tablewidget"));
tableWidget->maximumSize();
QStringList m_header;
m_header<<"item1"<<"item2";
tableWidget->setHorizontalHeaderLabels(m_header);
tableWidget->setItem(0,0,new QTableWidgetItem("Jan"));
tableWidget->setItem(1,0,new QTableWidgetItem("Feb"));
tableWidget->setItem(2,0,new QTableWidgetItem("Feb"));
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(tableWidget);
setLayout(layout);
}*/
TestTbTab::TestTbTab(const QFileInfo &fileInfo, QWidget *parent) : QWidget(parent)
{
model = new TableModel(this);
grid_layout = new QGridLayout;
tab = new QWidget;
view = new QTableView(tab);
view->setModel(model);
view->setWindowTitle(QObject::tr("test designed Model"));
grid_layout->addWidget(view);
setLayout(grid_layout);
}
To copy to clipboard, switch view to plain text mode
thanks for any advise / suggestion
Bookmarks