Subclassing a model makes it possible to customize it in many ways: You can provide tooltips for the items, change the background color, provide calculated values, provide different values for viewing and editing, handle null values specially, and more. See the Query Model example for the complete source code. prepare( "update person set firstname = ? where id = ?") The following two functions make fields 1 and 2 of a query model editable:īool EditableSqlModel ::setFirstName( int personId, const QString &firstName) If you need a read-write model that operates on an arbitrary result set, you can subclass QSqlQueryModel and reimplement flags() and setData() to make it read-write. QSqlTableModel is optimized to operate on a single table at a time. See Model/View Programming for more information. You can create your own delegates by subclassing QAbstractItemDelegate or QItemDelegate. The delegate is also responsible for providing editor widgets (e.g., a combobox) when the user starts editing an item in the view. The default delegate, QItemDelegate, handles the most common data types ( int, QString, QImage, etc.). The items in the view are rendered using a delegate. Likewise, if you remove rows using removeRows(), the rows will be marked with an exclamation mark (!) until the change is submitted. If you insert rows programmatically using QSqlTableModel::insertRows(), the new rows will be marked with an asterisk (*) until they are submitted using submitAll() or automatically when the user moves to another record (assuming the edit strategy is QSqlTableModel::OnRowChange). QTableView also has a vertical header on the left with numbers identifying the rows. Model - >setHeaderData( 3, Qt ::Horizontal, QObject ::tr( "Country")) Model - >setHeaderData( 2, Qt ::Horizontal, QObject ::tr( "City")) Model - >setHeaderData( 1, Qt ::Horizontal, QObject ::tr( "Name")) Model - >setHeaderData( 0, Qt ::Horizontal, QObject ::tr( "ID"))
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |