Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How do you handle these cases?



  • Hi, I've a couple of doubts:
    1 - When you works with databases, how do you transport secondary data or data not to be displayed (like records id and other) for each records?
    In my specific case, I work with QTableWidget and I do this inserting the secondary data in hided columns.
    What do you think about it?

    2 - I am going crazy with columns width in QTableWidget.
    I've 3 column and I would like the first to be wider than the other two.
    To do this, I've setColumnWith for 2nd and 3nd column at my discrection and for first column, I set width taking QTableWidget width and subtracting width of 2nd and 3nd columns.
    The result is that the 3nd column exits QTableWidget.
    If I set first columnd at my discrection, the risk is that 3nd column will be too large or too tight.
    How do you handle these cases?

    Grazie.



  • to point (1): I never move SQL rerieved data directly to a Qt widget. I always create a transaction model class to abstract the access to the database into well defined and discrete transactions, and create methods specifically to provide only the needed data. As for how to link the table data to a specific (nondisplayed) record number, you can probably subclass the table cell to contain display data and hidden metadata.

    Cannot speak to the other points because I don't generally use that widget.



  • @Stefanoxjx
    In addition to @Kent-Dorfman. If retrieving from a database I would not normally choose a QTableWidget. That is a wrapper around QTableView, and includes its own data model. You are going to have to copy your data out of, say, a QSqlTableModel and into the QTableView, and vice versa if you allow editing. I would use a QTableView against the data model fetched.


  • Moderators

    @Stefanoxjx said in How do you handle these cases?:

    1 - When you works with databases, how do you transport secondary data or data not to be displayed (like records id and other) for each records?
    In my specific case, I work with QTableWidget and I do this inserting the secondary data in hided columns.
    What do you think about it?

    I think (but take it with a grain of salt) that the widget item allows for "user data" to be stored. I personally never use the widgets built upon the views. I'd always opt for a model of my making and a regular Q*View.


Log in to reply