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. Display QTableView on mainwindow.
Forum Updated to NodeBB v4.3 + New Features

Display QTableView on mainwindow.

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.4k Views
  • 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.
  • O Offline
    O Offline
    ozzy
    wrote on last edited by
    #1
    #include "mainwindow.h"
    #include <QStandardItemModel>
    #include <QTableView>
    #include <QModelIndex>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        QStandardItemModel model(4,2);
        QTableView *tableView = new QTableView;
    
        tableView->setModel(&model);
    
        MainWindow w;
       
        return a.exec();
    }
    

    I only konw how to display widget on mainwindow use function setCentralWidget(). But how to display View on mainwindow?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mawh1960
      wrote on last edited by
      #2

      Hi,

      Your tableView is a widget, so try

      w.setCentralWidget(tableView);
      
      O 1 Reply Last reply
      1
      • M mawh1960

        Hi,

        Your tableView is a widget, so try

        w.setCentralWidget(tableView);
        
        O Offline
        O Offline
        ozzy
        wrote on last edited by
        #3

        @mawh1960

        Qt 4.8 version
        compile without problem, but no window pop out.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mawh1960
          wrote on last edited by
          #4

          You're missing

            w.show();
          
          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