C++ (Qt)model = new QStandardItemModel(0, 3, this); ui->tableView->setSortingEnabled(true);ui->tableView->sortByColumn(1, Qt::DescendingOrder); //ui->tableView->horizontalHeader()->setStretchLastSection(true);//ui->tableView->setMaximumWidth(500);//ui->tableView->horizontalHeader()->setResizeMode(QHeaderView::Stretch);//ui->tableView->horizontalHeader()->setResizeMode(1, QHeaderView::Interactive);//ui->tableView->horizontalHeader()->resizeSection(1, 250);//ui->tableView->horizontalHeader()->setMaximumSize(50, 50); //model->setHeaderData(0, Qt::Horizontal, QObject::tr("№"));model->setHeaderData(0, Qt::Horizontal, QObject::tr("Номер"));model->setHeaderData(1, Qt::Horizontal, QObject::tr("Баланс"));model->setHeaderData(2, Qt::Horizontal, QObject::tr("Время парсинга")); //model->setHorizontalHeaderLabels(QStringList() << "Номер" << "Баланс" << "Время парсинга"); ui->tableView->setModel(model);
C++ (Qt) model->insertRow(iterationCount); model->setData(model->index(iterationCount, 0), phone); QColor color; if (balanse < 10) { color = Qt::red; } else if (balanse > 10 && balanse < 50) { color = Qt::darkRed; } else if (balanse > 50 && balanse < 100) { color = Qt::darkBlue; } else { color = Qt::darkGreen; } model->setData(model->index(iterationCount, 1), QColor(color), Qt::ForegroundRole); model->setData(model->index(iterationCount, 1), balanse); model->setData(model->index(iterationCount, 2), timeElapsed);
C++ (Qt)ui->tableView->setSpan(iterationCount, 0, 1, 3);model->insertRow(iterationCount);model->setData(model->index(iterationCount, 0), timeAllStr);
C++ (Qt)ui->tableView->horizontalHeader()->setMinimumSectionSize(1, 100);ui->tableView->horizontalHeader()->setResizeMode(1, QHeaderView::ResizeToContents);
C++ (Qt)MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){ ui->setupUi(this); QTextCodec *codec = QTextCodec::codecForName("UTF-8"); QTextCodec::setCodecForCStrings(codec); QTextCodec::setCodecForTr(codec); model = new QStandardItemModel(0, 3, this); // model->setHeaderData(0, Qt::Horizontal, tr("Номер"));// model->setHeaderData(1, Qt::Horizontal, tr("Баланс"));// model->setHeaderData(2, Qt::Horizontal, tr("Время парсинга")); model->setHorizontalHeaderLabels(QStringList() << "Номер" << "Баланс" << "Время парсинга"); //ui->tableView->setContextMenuPolicy(Qt::DefaultContextMenu); ui->tableView->setModel(model); ui->tableView->setSortingEnabled(true); ui->tableView->sortByColumn(1, Qt::DescendingOrder); ui->tableView->horizontalHeader()->resizeSection(0, 200); ui->tableView->horizontalHeader()->resizeSection(1, 100); ui->tableView->horizontalHeader()->setStretchLastSection(true);}