From 7c945b69cef654600d9969e16d0a57e9b30c3fb1 Mon Sep 17 00:00:00 2001 From: khamidou Date: Sun, 24 Jul 2011 15:27:12 +0200 Subject: [PATCH] added a timer widget --- mainwindow.cpp | 15 +++++++++++---- startstopwidget.cpp | 6 ++++++ startstopwidget.h | 18 ++++++++++++++++++ tabledelegate.cpp | 19 ++++++++++++++----- tabledelegate.h | 8 ++++---- tt.pro | 9 ++++++--- 6 files changed, 59 insertions(+), 16 deletions(-) create mode 100644 startstopwidget.cpp create mode 100644 startstopwidget.h diff --git a/mainwindow.cpp b/mainwindow.cpp index 8d30932..3ec49d8 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -16,7 +16,7 @@ MainWindow::MainWindow(QWidget *parent) : createActions(); createToolbar(); - setCentralWidget(tabWidget); + setCentralWidget(tabWidget); } void MainWindow::setUpTableView() @@ -36,6 +36,15 @@ void MainWindow::setUpTableView() tableView->horizontalHeader()->moveSection(2, 0); tableView->horizontalHeader()->resizeSections(QHeaderView::ResizeToContents); tableView->horizontalHeader()->setStretchLastSection(true); + + /* Set up the widgets */ + for(int i = 0; i < model->rowCount(); i++) { + QPushButton *b = new QPushButton(tr("Poussez moi !"), tableView); + tableView->setIndexWidget(model->index(i, 1), b); + } + + + } void MainWindow::createActions() @@ -58,8 +67,7 @@ void MainWindow::createToolbar() } void MainWindow::insertRow() -{ - qDebug() << "paf"; +{ QSqlQuery query; /* FIXME : don't hardcode field numbers */ @@ -81,7 +89,6 @@ void MainWindow::deleteRows() { } model->select(); - qDebug() << "ho"; } MainWindow::~MainWindow() diff --git a/startstopwidget.cpp b/startstopwidget.cpp new file mode 100644 index 0000000..2d7f3d2 --- /dev/null +++ b/startstopwidget.cpp @@ -0,0 +1,6 @@ +#include "startstopwidget.h" + +StartStopWidget::StartStopWidget(QWidget *parent) : + QWidget(parent) +{ +} diff --git a/startstopwidget.h b/startstopwidget.h new file mode 100644 index 0000000..8f64cc4 --- /dev/null +++ b/startstopwidget.h @@ -0,0 +1,18 @@ +#ifndef STARTSTOPWIDGET_H +#define STARTSTOPWIDGET_H + +#include + +class StartStopWidget : public QWidget +{ +Q_OBJECT +public: + StartStopWidget(QWidget *parent = 0); + +signals: + +public slots: + +}; + +#endif // STARTSTOPWIDGET_H diff --git a/tabledelegate.cpp b/tabledelegate.cpp index 98eea96..0eb85bd 100644 --- a/tabledelegate.cpp +++ b/tabledelegate.cpp @@ -2,7 +2,7 @@ #include TableDelegate::TableDelegate(QWidget *parent) : - QStyledItemDelegate(parent) + QSqlRelationalDelegate(parent) { } @@ -20,17 +20,26 @@ QWidget *TableDelegate::createEditor(QWidget *parent, return lWidget; } else { - return QStyledItemDelegate::createEditor(parent, option, index); + return QSqlRelationalDelegate::createEditor(parent, option, index); } } -/* FIXME: rendre propre void TableDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { - + if (index.column() == 2) { /* + StarRating starRating = qVariantValue(index.data()); + + if (option.state & QStyle::State_Selected) + painter->fillRect(option.rect, option.palette.highlight()); + + starRating.paint(painter, option.rect, option.palette, + StarRating::ReadOnly); + */ + } else { + QSqlRelationalDelegate::paint(painter, option, index); + } } -*/ QSize TableDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { } diff --git a/tabledelegate.h b/tabledelegate.h index a14f926..ddff03d 100644 --- a/tabledelegate.h +++ b/tabledelegate.h @@ -2,20 +2,20 @@ #define TABLEDELEGATE_H #include -#include +#include #include #include -class TableDelegate : public QStyledItemDelegate +class TableDelegate : public QSqlRelationalDelegate { Q_OBJECT public: TableDelegate(QWidget *parent = 0); - /* void paint(QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index) const; */ + void paint(QPainter *painter, const QStyleOptionViewItem &option, + const QModelIndex &index) const; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const; QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, diff --git a/tt.pro b/tt.pro index e9b5eb7..88b929e 100644 --- a/tt.pro +++ b/tt.pro @@ -2,15 +2,18 @@ # Project created by QtCreator 2011-06-25T14:16:34 # ------------------------------------------------- QT += network \ - xml sql + xml \ + sql TARGET = tt TEMPLATE = app SOURCES += main.cpp \ mainwindow.cpp \ taskmodel.cpp \ - tabledelegate.cpp + tabledelegate.cpp \ + startstopwidget.cpp HEADERS += mainwindow.h \ taskmodel.h \ - tabledelegate.h + tabledelegate.h \ + startstopwidget.h FORMS += OTHER_FILES += README.txt -- 2.43.0