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.9k 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 3 Jan 2021, 04:52 last edited by _jao_victor_ 1 Mar 2021, 04:52
    #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.

    J 1 Reply Last reply 3 Jan 2021, 07:58
    0
    • _ _jao_victor_
      3 Jan 2021, 18:38

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

      J Offline
      J Offline
      JonB
      wrote on 4 Jan 2021, 08:01 last edited by JonB 1 Apr 2021, 08:02
      #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_
        3 Jan 2021, 04:52

        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.

        J Offline
        J Offline
        JonB
        wrote on 3 Jan 2021, 07:58 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 3 Jan 2021, 15:47 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 3 Jan 2021, 18:38
          1
          • S SGaist
            3 Jan 2021, 15:47

            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 3 Jan 2021, 18:38 last edited by
            #4

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

            J 1 Reply Last reply 4 Jan 2021, 08:01
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 3 Jan 2021, 19:30 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_
                3 Jan 2021, 18:38

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

                J Offline
                J Offline
                JonB
                wrote on 4 Jan 2021, 08:01 last edited by JonB 1 Apr 2021, 08:02
                #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 6 Jan 2021, 04:20 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

                  1/7

                  3 Jan 2021, 04:52

                  • Login

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