Results 1 to 4 of 4

Thread: QTableView with QSqlTableModel - change widget for edit data

  1. #1
    Join Date
    Aug 2010
    Location
    Poland - Koszalin/Poznań
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QTableView with QSqlTableModel - change widget for edit data

    Hi,

    I have some piece of code which load data form single mysql table to table view. This data should be editable, so I`m using QSqlTableModel. But I want to change default widget to edit data, for example I have enum type in database with values "Yes" and "No" and for this item i want to have combobox widget with these values. Another example is field with possible integer values 0 and 1, here I want to have checkbox in table view. How to reach this? Maybe subclassing QTableView, but I have no idea how to do this.

  2. #2
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView with QSqlTableModel - change widget for edit data

    Inherit QSqlTableView add custom delegate that will display "Yes" "NO".That Delegate should return data type stored in db e.g. bool, char or int. As fare as I remember QSqlTableView there is example how to connect lookup tables to columns which results in automatically displayed combo-box on edit.

    To understand model view programing in Qt read Model/View Programming and An Introduction to Model/View Programming.

    I also believe that default edit delegate for bool type is check-box. If your model return bool for edit role check box should be displayed.

  3. The following user says thank you to pervlad for this useful post:

    elektrrrus (9th August 2010)

  4. #3
    Join Date
    Aug 2010
    Location
    Poland - Koszalin/Poznań
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView with QSqlTableModel - change widget for edit data

    Very thanks for aswer, it solve my problems.

  5. #4
    Join Date
    Nov 2010
    Posts
    142
    Thanks
    24
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView with QSqlTableModel - change widget for edit data

    Hi elektrrrus,

    I am trying to do exactly the same but I am totally lost among tutorials, examples and documentation.
    No solution so far. Could you please provide the code that created the model you described at the initial post?
    Thanks in advance.

Similar Threads

  1. QTableView line edit clears the text on edit
    By PlasticJesus in forum Qt Programming
    Replies: 5
    Last Post: 14th March 2015, 20:06
  2. Replies: 1
    Last Post: 2nd May 2010, 00:03
  3. QTableView, QSqlTableModel - data disappears
    By msh in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2008, 12:50
  4. QSqlTableModel cannot change values
    By raphaelf in forum Newbie
    Replies: 2
    Last Post: 23rd May 2007, 09:01
  5. Replies: 8
    Last Post: 15th May 2007, 10:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.