Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to use FreezeTableWidget-Example [SOLVED]

How to use FreezeTableWidget-Example [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mr. Kibu
    wrote on last edited by Mr. Kibu
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 use

      QTableView ->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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Mr. Kibu
        wrote on last edited by
        #3

        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!!!!

        mrjjM 1 Reply Last reply
        0
        • M Mr. Kibu

          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!!!!

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          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,

          1 Reply Last reply
          0
          • M Offline
            M Offline
            Mr. Kibu
            wrote on last edited by
            #5

            It works! I added a layout and than the widget like this:

            ui->layVouchPos->addWidget(freezeTab);

            Thanks!!

            mrjjM 1 Reply Last reply
            0
            • M Mr. Kibu

              It works! I added a layout and than the widget like this:

              ui->layVouchPos->addWidget(freezeTab);

              Thanks!!

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Mr.-Kibu
              Super. good luck with project.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved