How to use FreezeTableWidget-Example [SOLVED]
-
Hello!
I want to use the FreezeTableWidget in my Qt-Application.
I have got a QTableView that shows the data from my SQLite-Database, added the FreezeTableWidget (.h and .cpp) to my project and included the "FreezeTableWidget.h" in the MainWindow (here is the QTableView).
Than I promoted the QTableView to the FreezeTableWidget. But if I run the project I get the error:/home/franz/Dokumente/IT/QT/Projekte/BiFF/Build/ui_mainwindow.h:74: error: no matching function for call to 'FreezeTableWidget::FreezeTableWidget(QWidget*&)'
mytableView = new FreezeTableWidget(centralWidget);How do I use the FreezeTableWidget-Exampe correct in my project.
Thank you
Franz
-
It seems like the constructor for FreezeTableWidget wants a "QAbstractItemModel" as param.
And you give it centralWidget.If you look in the main.cpp file you see they do like this
QStandardItemModel *model=new QStandardItemModel(); ...fill the model... FreezeTableWidget *tableView = new FreezeTableWidget(model); tableView->resize(560, 680); tableView->show();
So I not sure you can use the promote feature directly (since it wants a QWidget * Parent)
but you should be able to useQTableView ->model() in new FreezeTableWidget( QTableView ->model() ) ;
to make it use same model.
But as i see the main program, it is a standalone widget/ full QTableView for it self so I guess you want to
use it instead of QTableView . But you need the same model as you use with the QTableView. -
But as i see the main program, it is a standalone widget/ full QTableView for it self so I guess you want to
use it instead of QTableView . But you need the same model as you use with the QTableView.
You are right. I want to use the FreezeTableWidget in an existing Mainwindow. I have already included the FreezeTableWidget into my MainWindow-Class and added
FreezeTableWidget *freezeTab = new FreezeTableWidget(mModelVoucher);
to the constructor.
But how does it works, to show the FreezeTable in my MainWindow. Witch object do I have to include in my mainwindow.ui and how do I connect my "freezeTab" (=the FreezeTableWidget) with the object in the mainwindow.ui??
Thank you for your help!!!!
-
hi
Well depends a bit on what you have in your mainwindow already.
Normally one would insert widgets into a layout for the window.
But let us assume you just want to place it
in the mainwindow,
it would be enough just to set the size and position and assign the mainwindow as parent.#include "mainwindow.h" #include "ui_mainwindow.h" #include "freezetablewidget.h" #include <QStandardItemModel> MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QStandardItemModel *model=new QStandardItemModel(); // just fill model with something for (int row = 0; row < 4; ++row) { for (int column = 0; column < 4; ++column) { QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); model->setItem(row, column, item); } } FreezeTableWidget *tableView = new FreezeTableWidget(model); tableView->setGeometry(10,10,200,200);// size and placement tableView->setParent(this); // or layout()->insertWidget(tableView) if mainwin have layout. }
Note, for your real application, you might want to put " FreezeTableWidget *tableView " in the MainWindow class as a member so you can connect signal etc.
signals etc to it,
-
It works! I added a layout and than the widget like this:
ui->layVouchPos->addWidget(freezeTab);
Thanks!!
-
@Mr.-Kibu
Super. good luck with project.