Created
September 13, 2012 14:20
-
-
Save Atsushi4/3714617 to your computer and use it in GitHub Desktop.
QtのItemViewの規定動作確認。setしたデータの型によってsortの挙動やDelegateが変わる。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
継承もmocも要らないので書き直した。