Skip to content

Instantly share code, notes, and snippets.

@Atsushi4
Created September 13, 2012 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Atsushi4/3714617 to your computer and use it in GitHub Desktop.
Save Atsushi4/3714617 to your computer and use it in GitHub Desktop.
QtのItemViewの規定動作確認。setしたデータの型によってsortの挙動やDelegateが変わる。
#include <QTableWidget>
#include <QDateTime>
#include <QApplication>
static void init(QTableWidget &w) {
w.setSortingEnabled(true);
w.setRowCount(10);
w.setColumnCount(10);
w.resize(640, 480);
QTableWidgetItem *item;
for (int i = 0; i < w.rowCount(); ++i) {
w.setItem(i, 0, new QTableWidgetItem(QString::number(i - 5)));
w.setItem(i, 1, item = new QTableWidgetItem); item->setData(Qt::EditRole, i - 5);
w.setItem(i, 2, item = new QTableWidgetItem); item->setData(Qt::EditRole, i - 4.5);
w.setItem(i, 3, item = new QTableWidgetItem); item->setData(Qt::EditRole, QDateTime::currentDateTime().addDays(i));
}
w.resizeColumnsToContents();
}
int main(int argc, char **argv)
{
QApplication app(argc, argv);
QTableWidget w;
init(w);
w.show();
return app.exec();
}
@Atsushi4
Copy link
Author

継承もmocも要らないので書き直した。

@Atsushi4
Copy link
Author

継承もmocも要らないので書き直した。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment