Delegate zeigt icons nicht
Verfasst: 25. Januar 2008 17:02
hi
seitdem ich ein Delegate für den QTreeView integriert habe will es die icons für den Status nicht mehr anzeigen, ohne den Delegate geht es ohne Probleme
hier den Status vom Download.cpp:
hier im multiview.cpp ist SYMBOL schon definiert
multiview.h:
schon mit den SYMBOL aktiviert und jede menge rum probiert ging aber nicht.
seitdem ich ein Delegate für den QTreeView integriert habe will es die icons für den Status nicht mehr anzeigen, ohne den Delegate geht es ohne Probleme
hier den Status vom Download.cpp:
Code: Alles auswählen
#include "download.h"
#include "downloadfileevent.h"
#include "downloadstatusevent.h"
#include "downloadthread.h"
#include "DLListDelegate.h"
#include <QEvent>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QModelIndex>
#include <QFile>
#include <QTextStream>
Download::Download(QStandardItemModel *model, QString fname, unsigned long fsize, QString fhash, QString fhost)
: QObject(0),
name( fname ),
size( fsize ),
hash( fhash ),
m_host( fhost ),
dlThread( NULL ),
queueState( DownloadQueue::QUEUED ),
model( model ),
routeQuality( -1 ),
currentSize( 0 ),
currentRate( 0 ),
nbStart( 0 )
{
void Download::setStatus( int status )
{
int c = myRow();
switch( status )
{
case DOWNLOADSTATUS_CONNECTING:
model->setData(model->index(c,7), tr("Connecting"));
model->setData(model->index(c,SYMBOL), QIcon(QString::fromUtf8(":/resources/connecting.png")), Qt::DecorationRole);
break;
case DOWNLOADSTATUS_DOWNLOADING:
model->setData(model->index(c,7), tr("Downloading"));
model->setData(model->index(c,SYMBOL), QIcon(QString::fromUtf8(":/resources/down.png")), Qt::DecorationRole);
break;
}
}Code: Alles auswählen
#include <QList>
#include <QtDebug>
#include <QContextMenuEvent>
#include <QMenu>
#include <QVBoxLayout>
#include <QIcon>
#include <QStandardItemModel>
#include <QModelIndex>
#include <QHeaderView>
#include <QDir>
#include <QFileInfo>
#include "multiview.h"
#include "connectionevent.h"
#include "connectioncountevent.h"
#include "connectionattemptevent.h"
#include "download.h"
#include "DLListDelegate.h"
MultiView::MultiView(QWidget *parent)
: QWidget(parent)
{
setupUi(this);
DLListModel = new QStandardItemModel(0, 13);
DLListModel->setHeaderData(SYMBOL, Qt::Horizontal, tr("#"));
DLListModel->setHeaderData(NAME, Qt::Horizontal, tr("File Name"));
DLListModel->setHeaderData(SIZE, Qt::Horizontal, tr("Size"));
downloadsTreeView->setModel(DLListModel);
DLDelegate = new DLListDelegate(downloadsTreeView);
downloadsTreeView->setItemDelegate(DLDelegate);Code: Alles auswählen
int MultiView::addItem(QString symbol, QString name, qlonglong fileSize, double progress, double dlspeed, QString sources, QString status, QString routequality, QString host, QString hash, QString ptr, qlonglong completed, qlonglong remaining)
{
int row;
QString sl;
//QIcon icon(symbol);
name.insert(0, " ");
//sl.sprintf("%d / %d", seeds, leechs);
row = DLListModel->rowCount();
DLListModel->insertRow(row);
//DLListModel->setData(DLListModel->index(row, SYMBOL), QVariant((QIcon)icon), Qt::DecorationRole);
DLListModel->setData(DLListModel->index(row, NAME), QVariant((QString)name), Qt::DisplayRole);
DLListModel->setData(DLListModel->index(row, SIZE), QVariant((qlonglong)fileSize));
}
void MultiView::delItem(int row)
{
DLListModel->removeRow(row, QModelIndex());
}
void MultiView::editItem(int row, int column, QVariant data)
{
//QIcon *icon;
switch(column) {
//case SYMBOL:
/*icon = new QIcon(data.toString());*/
//DLListModel->setData(DLListModel->index(row, SYMBOL), QVariant((QIcon)*icon), Qt::DecorationRole);
//delete icon;
//break;
case NAME:
DLListModel->setData(DLListModel->index(row, NAME), data, Qt::DisplayRole);
break;
case SIZE:
DLListModel->setData(DLListModel->index(row, SIZE), data);
break;
}
}
double MultiView::getSpeed(int row, QStandardItemModel *model)
{
return model->data(model->index(row, DLSPEED), Qt::DisplayRole).toDouble();
}
QString MultiView::getFileName(int row, QStandardItemModel *model)
{
return model->data(model->index(row, NAME), Qt::DisplayRole).toString();
}
QString MultiView::getStatus(int row, QStandardItemModel *model)
{
return model->data(model->index(row, STATUS), Qt::DisplayRole).toString();
}Code: Alles auswählen
#include "ui_multiview.h"
#include <QFileDialog>
#include <QProgressBar>
#include <QtGui>
#include <QObject>
#include <QModelIndex>
#include <QVariant>
class Download;
class DLListDelegate;
class QStandardItemModel;
class MultiView : public QWidget, private Ui::MultiView
{
Q_OBJECT
public:
MultiView(QWidget *parent = 0);
~MultiView();
signals:
public slots:
int addItem(QString symbol, QString name, qlonglong size, double progress, double dlspeed, QString sources, QString status, QString routequality, QString host, QString hash, QString ptr, qlonglong completed, qlonglong remaining);
void delItem(int row);
void editItem(int row, int column, QVariant data);
double getSpeed(int row, QStandardItemModel *model);
QString getFileName(int row, QStandardItemModel *model);
private:
QStandardItemModel *DLListModel;
QItemSelectionModel *selection;
DLListDelegate *DLDelegate;
};