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. I use tableview to show data, but ??

I use tableview to show data, but ??

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 392 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.
  • D Offline
    D Offline
    Duy Khang
    wrote on last edited by Duy Khang
    #1

    Im trying to create a table where the user can edit the values in one column. The idea was that if the user double clicks ( or press and hold the mouse button) the value of one column turns into an edit field, where the value can be changed. If editing is finished (enter pressed or focus lost) the edit field should be hidden and the new value be shown. Also the new value should be sent to c++ by a signal.

    But i have problems how to realise this and where to start with it. I know how to handle the signals, doubleclick, pressAndHold events and all these stuff, but i have know idea how to combine it to get a table with the described behaviour :(

    Does anyone knows an example for this? Something that is near to my table.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rodrigo B.
      wrote on last edited by Rodrigo B.
      #2

      Hi @Duy-Khang ,

      Typically you can have such a table by using QTableWidget. Check the link for a simple explanation on how to use it.

      QTableWidget is very easy to use, but it stores the data in the widget itself. If you have an already defined data structure that you want to show in a table widget, then you need to use QTableView widget associated with a QAbstractItemModel (which interfaces with your already existing data structure). This is explained in Model/View programming.

      An example of Model/View programming that is very easy to understand is the Editable Tree Model. This example works with a tree, not a table, but it is very similar to what you would do with a table.

      The Table Model Example is also a simple example of using Model/View programming and it uses a table, but it doesn't show how to create a model because it uses Qt's already available QSqlTableModel. It does show however how to create a table view that allows you to edit data.

      Note that you can easily open and run Qt's examples if you run QtCreator. You can simply click on "Examples" on the Welcome screen and select which example you would like to open.

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Duy Khang
        wrote on last edited by
        #3

        but i want to use table view with QSqlQueryModel, how can i do it ?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rodrigo B.
          wrote on last edited by
          #4

          The first lines of the documentation of QSqlQueryModel contain an example of how to show the results of a query in a table view.

          1 Reply Last reply
          1
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            You can use https://github.com/VSRonin/QtModelUtilities , this examples shows you what to do: https://github.com/VSRonin/QtModelUtilities/blob/master/examples/exam_RoleMaskProxyModel/exam_rolemaskeditablesql.cpp

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2

            • Login

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