My listView + QStyledItemDelegate don't show to me any info

69 Views Asked by At

I'm training use listView and qStyledItemDelegate. I try this ( my code dropmefiles.com.ua/ru/6KBSWD), but I don't understand what is wrong. It shows me just empty list

// cpp file

#include "WidgetDelegate.h"
#include "QtWidgets/qapplication.h"

MyStandartItemModel::MyStandartItemModel()
    : QStyledItemDelegate()
{

}

void MyStandartItemModel::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    if(index.column() == 1)
    {
        int progress = index.data().toInt();

        QStyleOptionProgressBar progressBar;
        progressBar.rect = option.rect;
        progressBar.minimum = 0;
        progressBar.maximum = 100;
        progressBar.progress = progress;
        progressBar.text = QString::number(progress) = "%";
        progressBar.textVisible = true;

        QApplication::style()->drawControl(QStyle::CE_ProgressBar,
                                           &progressBar, painter);
    }
    else { QStyledItemDelegate::paint(painter, option, index); }
}

QSize MyStandartItemModel::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
    return QSize(300, 300);
}

// mainWindow

#include "mainwindow.h"
#include "QtWidgets/qtreeview.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    
    MyStandartItemModel* myDelegate = new MyStandartItemModel();
    ui->listView->setItemDelegate(myDelegate);
}

MainWindow::~MainWindow()
{
    delete ui;
}

I took this code from https://doc.qt.io/qt-5/qabstractitemdelegate.html#details

0

There are 0 best solutions below