I copied qt designers' SheetDelegate class with some modification to show sheets like what's in designers' widgetbox. But the compiler says "StencilView.cpp:21: undefined reference to `SheetDelegate::SheetDelegate(QObject*)' ".
Modified SheetDelegate.h
Code:
#ifndef SHEET_DELEGATE_H #define SHEET_DELEGATE_H #include <QStyledItemDelegate> class SheetDelegate: public QStyledItemDelegate { Q_OBJECT public: virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const; }; #endif // SHEET_DELEGATE_H
Modified SheetDelegate.cpp
Code:
#include <QtGui/QStyle> #include <QtGui/QPainter> : QStyledItemDelegate(parent) { } void SheetDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { if (index.model()->parent(index).isValid()) { // this is a top-level item. QStyleOptionButton buttonOption; buttonOption.state = option.state; #ifdef Q_WS_MAC #endif buttonOption.rect = option.rect; buttonOption.palette = option.palette; QStyleOption branchOption; static const int i = 9; // ### hardcoded in qcommonstyle.cpp branchOption.palette = option.palette; if (parent->isExpanded(index)) // draw text index.model()->data(index, Qt::DisplayRole).toString()); option.palette, parent->isEnabled(), text); } else { QStyledItemDelegate::paint(painter, option, index); } } { QStyleOptionViewItem option = opt; return sz; }
The StencilView class is defined as a QWidget class where shows the result.
StencilView.h
Code:
#ifndef STENCILVIEW_H #define STENCILVIEW_H #include "SheetDelegate.h" #include <QWidget> class StencilSelector; class QFileSystemModel; class QSortFilterProxyModel; class QTreeView; class QLineEdit; class QPushButton; class SheetDelegate; { Q_OBJECT public: StencilView(StencilSelector *parent); private slots: void reapplyFilter(); private: QTreeView *treeView; SheetDelegate *delegate; QFileSystemModel *sourceModel; QSortFilterProxyModel *proxyModel; QLineEdit *filterLineEdit; QPushButton *moreButton; }; #endif
StencilView.cpp
Code:
#include <QtGui> #include "StencilView.h" #include "StencilSelector.h" { sourceModel = new QFileSystemModel; sourceModel->setReadOnly(true); //sourceModel->setNameFilters(QStringList::QStringList("*.odg")); sourceModel->setNameFilterDisables(false); sourceModel->setRootPath("/home/yue/stencils_test"); //QModelIndex index = sourceModel->rootPath(); proxyModel->setSourceModel(sourceModel); proxyModel->setFilterKeyColumn(-1); proxyModel->setDynamicSortFilter(true); delegate = new SheetDelegate(this); treeView->setModel(proxyModel); treeView->setItemDelegate(delegate); /*treeView->header()->setStretchLastSection(true); treeView->header()->setSortIndicator(0, Qt::AscendingOrder); treeView->header()->setSortIndicatorShown(true); treeView->header()->setClickable(true); */ //treeView->setRootIndex(proxyModel->mapFromSource(index)); this, SLOT(reapplyFilter())); interLayout->addWidget(moreButton); interLayout->addWidget(filterLineEdit); mainLayout->addLayout(interLayout); mainLayout->addWidget(treeView); setLayout(mainLayout); //filterLineEdit->setText(tr("<Filter>")); //setWindowTitle(tr("Stencil View")); } void StencilView::reapplyFilter() { proxyModel->setFilterRegExp(regExp); } #include <StencilView.moc>
Could anyone point out what's wrong there?
