如何将QDATE添加到QTableView
How to add qdate to qtableview
我想在表中添加 Qdate
说 QTableview
。问题是,如果我将其转换为字符串,我可以添加和检索数据。但我只想将日期存储在我的模型中。
void MainWindow::setUpTabel()
{
QDateTime myDate;
myDate.setDate(QDate::currentDate());
//myModel
QStandardItemModel model = new QStandardItemModel(this);
QStandardItem *item = new QStandardItem;
item.setData(myDate,Qt::UserRole);
//Myview is also created and set the model to it
m_tableView->setModel(model);
}
问题是我无法在表中看到日期。
正如文档所说,您必须将项目设置为指定要设置项目的行和列的模型。
http://qt-project.org/doc/qt-4.8/qstandarditemmodel.html
修改您的代码:
void MainWindow::setUpTabel()
{
int row = 0, column = 0; // here you decide where is the item
QDateTime myDate;
myDate.setDate(QDate::currentDate());
QStandardItemModel model = new QStandardItemModel(this);
QStandardItem *item = new QStandardItem(myDate);
model.setItem(row, column, item);
m_tableView->setModel(model);
}
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 如何在C++中从两个单独的for循环中添加两个数组
- POCO::PostgreSQL:如何将std::vector支持添加到`Binder::bind`
- 如何仅为一个函数添加延迟
- 如何防止 c++ 在从浮点型转换为双精度型(不适用于 IO)时添加额外的小数?
- 使用std::transform将一个范围的元素添加到另一个范围中
- 如何将更多文件夹添加到c++include路径
- 如何将元素添加到数组的线程安全函数?
- QT通过C++添加映射QML项目
- 将QIcon添加到QTableView单元格
- qtableView 在订购项目到达时添加和显示它们任意?
- 将自定义样式添加到 QTableview 中添加的按钮
- Qt:是否可以将QVBoxLayout添加到QTableView
- 如何将QDATE添加到QTableView
- QTableView 滚动到新添加的行
- 如何在单击按钮时将字符串和int添加到QTableView
- 在QTableView中添加行会在大量插入后减慢应用程序的速度
- 如何在加载数据库时在QTableView中添加QPushButton
- QtableView中添加行的信号
- 在QTableView的自定义模型中添加和删除项目