@norobro
Hi norobro,
Thanks for this post. I will definitely try it.
----------
@Chris.
Unfortunately,
setLayout(tableLay);
setLayout(tableLay);
To copy to clipboard, switch view to plain text mode
is not working.
I did also try to inherit from QWidget, like I would make a single application, and add QTableView widget to it and set everything in roughly similar way to you in your last post. It also did not work. I have an impression I did everything like you did in your post. Yet, the result is exactly the same as before. There are two things that really are bothering me. First is that nothing I do cause any effect. The second is that I also set a title of that extra window with a table. Surprisingly, the title is the same as the title of my application application.
This is the code of the new class:
tableview.h
#ifndef TABLEVIEW_H
#define TABLEVIEW_H
#include <QWidget>
#include <QDialog>
#include <QVBoxLayout>
#include <QList>
#include <QTableView>
#include "../stworz_plik/rekord.h"
{
Q_OBJECT
private:
public:
explicit TableView
(const QList<Wydarzenia
::Rekord>
& dbStoreToday,
QObject *parent
= 0);
signals:
public slots:
};
#endif // TABLEVIEW_H
#ifndef TABLEVIEW_H
#define TABLEVIEW_H
#include <QWidget>
#include <QDialog>
#include <QVBoxLayout>
#include <QList>
#include <QTableView>
#include "../stworz_plik/rekord.h"
class TableView : public QDialog
{
Q_OBJECT
private:
QTableView* tableView;
QVBoxLayout* tableLay;
public:
explicit TableView(const QList<Wydarzenia::Rekord>& dbStoreToday, QObject *parent = 0);
signals:
public slots:
};
#endif // TABLEVIEW_H
To copy to clipboard, switch view to plain text mode
and tableview.cpp
#include <QStandardItem>
#include <QStandardItemModel>
#include <QStringList>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QStringList>
#include <QLabel>
#include "tableview.h"
TableView
::TableView(const QList<Wydarzenia
::Rekord>
&dbStoreToday,
QObject *parent
)
const int maxRows = dbStoreToday.size();
tableLay->addWidget(tableView);
tableLay
->addWidget
(new QLabel("aaa",
this));
model
->setHorizontalHeaderItem
(0,
new QStandardItem(trUtf8
("Name")));
model
->setHorizontalHeaderItem
(1,
new QStandardItem(trUtf8
("Surname")));
model
->setHorizontalHeaderItem
(2,
new QStandardItem(trUtf8
("Event name")));
model
->setHorizontalHeaderItem
(3,
new QStandardItem(trUtf8
("Event date")));
model
->setHorizontalHeaderItem
(4,
new QStandardItem(trUtf8
("Remainder")));
for(int row = 0; row < maxRows; ++row) {
itemList << dbStoreToday[row].imie << dbStoreToday[row].nazwisko << dbStoreToday[row].nazwa_wyd
<< dbStoreToday[row].data_wyd.toString() << tr("%1").arg(dbStoreToday[row].przypomnienie);
for(int col = 0; col < 5; ++col) {
item->setEditable(false);
model->setItem(row,col,item);
}
}
tableView->setModel(model);
tableView->show();
setLayout(tableLay);
}
#include <QStandardItem>
#include <QStandardItemModel>
#include <QStringList>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QStringList>
#include <QLabel>
#include "tableview.h"
TableView::TableView(const QList<Wydarzenia::Rekord> &dbStoreToday, QObject *parent)
: QWidget(parent) {
const int maxRows = dbStoreToday.size();
tableView = new QTableView(this);
tableView->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Expanding);
tableLay = new QVBoxLayout(this);
tableLay->addWidget(tableView);
tableLay->addWidget(new QLabel("aaa",this));
QStandardItemModel* model = new QStandardItemModel(maxRows,5,this);
model->setHorizontalHeaderItem(0, new QStandardItem(trUtf8("Name")));
model->setHorizontalHeaderItem(1, new QStandardItem(trUtf8("Surname")));
model->setHorizontalHeaderItem(2, new QStandardItem(trUtf8("Event name")));
model->setHorizontalHeaderItem(3, new QStandardItem(trUtf8("Event date")));
model->setHorizontalHeaderItem(4, new QStandardItem(trUtf8("Remainder")));
for(int row = 0; row < maxRows; ++row) {
QStringList itemList;
itemList << dbStoreToday[row].imie << dbStoreToday[row].nazwisko << dbStoreToday[row].nazwa_wyd
<< dbStoreToday[row].data_wyd.toString() << tr("%1").arg(dbStoreToday[row].przypomnienie);
for(int col = 0; col < 5; ++col) {
QStandardItem* item = new QStandardItem(itemList[col]);
item->setEditable(false);
model->setItem(row,col,item);
}
}
tableView->setModel(model);
tableView->show();
setLayout(tableLay);
}
To copy to clipboard, switch view to plain text mode
and the new function is as follows:
void MyApp::showTabulatedEvents() {
upcomingEventsForToday(); // ustaw liste dbStoreToday
TableView* tableView = new TableView(dbStoreToday,this);
tableView->setWindowTitle("Upcoming events");
tableView->show();
}
void MyApp::showTabulatedEvents() {
upcomingEventsForToday(); // ustaw liste dbStoreToday
TableView* tableView = new TableView(dbStoreToday,this);
tableView->setWindowTitle("Upcoming events");
tableView->show();
}
To copy to clipboard, switch view to plain text mode
Bookmarks