Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to add columns in QTableView?
Forum Updated to NodeBB v4.3 + New Features

How to add columns in QTableView?

Scheduled Pinned Locked Moved Solved Qt for Python
7 Posts 3 Posters 4.4k Views 1 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.
  • _ Offline
    _ Offline
    _jao_victor_
    wrote on last edited by _jao_victor_
    #1

    Is it possible to add columns to a QTableView using qtDesiger?
    In QTableWidget just right-click to add columns and rows, is there something similar for QTableView?
    I didn't find many tutorials with QTableView on the internet and in documentation.

    I want to take data from an existing database and place it in this QTableView without the user being able to edit or change the table properties.

    JonBJ 1 Reply Last reply
    0
    • _ _jao_victor_

      @SGaist When you say model, do you mean a database table?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #6

      @_jao_victor_ said in How to add columns in QTableView?:

      When you say model, do you mean a database table?

      A model does not have to be a database, but it can be. A database is an example of a model. You cannot use a database or other model at design-time to populate a view's columns or rows in Qt Designer. You'd have to use a QTableWidget at design-time. And that means typing values/column headings into cells, not fetching them from a database.

      Using a QTableView attached to a model such as a database at runtime is no problem.

      1 Reply Last reply
      2
      • _ _jao_victor_

        Is it possible to add columns to a QTableView using qtDesiger?
        In QTableWidget just right-click to add columns and rows, is there something similar for QTableView?
        I didn't find many tutorials with QTableView on the internet and in documentation.

        I want to take data from an existing database and place it in this QTableView without the user being able to edit or change the table properties.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @_jao_victor_
        My experience is that there is little you can do with a QTableView in the Designer. You have to use the QTableWidget there if you want to do design-time things.

        But QTableWidget is not the same as QTableView. It is a wrapper around it, notably with its own, internal model structure. If you want to connect a table view to an existing database source QTableWidget is not an optimal choice.

        Since you want "without the user being able to edit or change the table properties", just connect the QTableView to the database model at runtime and it will have the same columns. Yes, you do not get to see it laid out at design-time.

        1 Reply Last reply
        1
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #3

          Hi,

          You cannot do that with Designer. QTableView requires a model so you'll have to do some coding to set it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          _ 1 Reply Last reply
          1
          • SGaistS SGaist

            Hi,

            You cannot do that with Designer. QTableView requires a model so you'll have to do some coding to set it.

            _ Offline
            _ Offline
            _jao_victor_
            wrote on last edited by
            #4

            @SGaist When you say model, do you mean a database table?

            JonBJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #5

              No, a model is not limited to a database.

              See here.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • _ _jao_victor_

                @SGaist When you say model, do you mean a database table?

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by JonB
                #6

                @_jao_victor_ said in How to add columns in QTableView?:

                When you say model, do you mean a database table?

                A model does not have to be a database, but it can be. A database is an example of a model. You cannot use a database or other model at design-time to populate a view's columns or rows in Qt Designer. You'd have to use a QTableWidget at design-time. And that means typing values/column headings into cells, not fetching them from a database.

                Using a QTableView attached to a model such as a database at runtime is no problem.

                1 Reply Last reply
                2
                • _ Offline
                  _ Offline
                  _jao_victor_
                  wrote on last edited by
                  #7

                  @JonB Is it possible to take the data from the table and store it in some Python structure, for example, a list and then put it in a QTableView?

                  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