這是從Qt的教程複製的類:爲什麼我的視圖不顯示標題?
class Window : public QWidget
{
Q_OBJECT
public:
Window();
void setSourceModel();
private slots:
void filterRegExpChanged();
void filterColumnChanged();
void sortChanged();
void addMail();
private:
QSortFilterProxyModel *proxyModel;
QStandardItemModel *model;
QGroupBox *sourceGroupBox;
QGroupBox *proxyGroupBox;
QTreeView *sourceView;
QTreeView *proxyView;
QCheckBox *filterCaseSensitivityCheckBox;
QCheckBox *sortCaseSensitivityCheckBox;
QLabel *filterPatternLabel;
QLabel *filterSyntaxLabel;
QLabel *filterColumnLabel;
QLineEdit *filterPatternLineEdit;
QComboBox *filterSyntaxComboBox;
QComboBox *filterColumnComboBox;
QPushButton* button;
};
這是一個構造函數的DEF:
Window::Window()
{
model = new QStandardItemModel(this);
//HEADERS ARE NOT DISPLAYED EVEN THOUGH I'M SETTING THEM HERE
model->setHeaderData(0, Qt::Horizontal, QObject::tr("Subject"));
model->setHeaderData(1, Qt::Horizontal, QObject::tr("Sender"));
model->setHeaderData(2, Qt::Horizontal, QObject::tr("Date"));
proxyModel = new QSortFilterProxyModel;
proxyModel->setDynamicSortFilter(true);
sourceView = new QTreeView;
sourceView->setRootIsDecorated(false);
sourceView->setAlternatingRowColors(true);
proxyView = new QTreeView;
proxyView->setRootIsDecorated(false);
proxyView->setAlternatingRowColors(true);
proxyView->setModel(proxyModel);
proxyView->setSortingEnabled(true);
connect(button,SIGNAL(clicked()),this,SLOT(addMail()));//THIS SEEMS NOT TO MAKE ANY DIFFERENCE - NOTHING IS ADDED
};
void Window::addMail()
{
model->insertRow(0);
model->setData(model->index(0, 0), "subject");
model->setData(model->index(0, 1), "sender");
model->setData(model->index(0, 2), "date");
}
void Window::setSourceModel()
{
proxyModel->setSourceModel(model);
sourceView->setModel(model);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Window window;
window.setSourceModel();
window.show();
return app.exec();
}
經由addMail加入既不頭也不數據被顯示。爲什麼?
監視默認值 – beyrem