Skip to content
  • 0 Votes
    20 Posts
    585 Views
    SGaistS

    You can implement a debouncer. For example, accumulate a certain amount of changes and only then signal that the model has changed to minimize the amount of time the views will query the model.
    Also, don't forget to properly use lock mechanism to avoid writing to the same object from multiple different threads.

  • 0 Votes
    34 Posts
    2k Views
    J

    Finally: I removed the call to a new QHeaderView and the header now works! -- it responds to mouse clicks!!
    Thank you!!

  • 0 Votes
    4 Posts
    343 Views
    kshegunovK

    @johnco3 said in cannot get fixed sized columns in QTableView to work.:

    perhaps it has to do with settings fixed on the last column which really needs to be Stretch to use the remaining horizontal space?

    Yes, it does. I think to make it really a fixed size you might need to set the minimum and maximum size to the same thing.

  • 0 Votes
    1 Posts
    175 Views
    No one has replied
  • 0 Votes
    5 Posts
    1k Views
    O

    @SGaist @JonB With inspiration from QTableWidget sources my approach for internal reordering is now to override dropEvent and in there use moveRows.

    if (event->source() == this) { // It's an internal move, a solution based on overridden QAbstractItemModel::moveRows

    That works for internal reordering.

    It seems like QDrag::exec is supposed to return an action performed but I find no information on how the information about a successful drop shall get back to the source widget and also the call to QDrag::exec is buried deep within a mouse event handler for QAbstractItemView.

    My solution is to also implement copy-or-move in an overridden dropEvent. First let the base class process the drop event. If accepted then check keyboard modifers. If not ctrl modifier, i.e. if move, then use the event source to find the source widget and call remove on the source widget.

  • 0 Votes
    4 Posts
    2k Views
    L

    @VRonin

    Thanks, a written example is a lot easier to understand. I was going through the Qt documentation over and over and couldn't find an good example for this.

  • 0 Votes
    4 Posts
    382 Views
    JonBJ

    @zloi_templar
    I don't understand:

    Why are you "saving" (whatever you mean by that) a number as a string? You're asking for trouble, save it as a number.

    Is using toFloat() a good idea? floats have limited precision, at least use toDouble()/doubles?

    Even then you will lose accuracy. The only "safe" way to store accurate floating point numbers in a database is via its decimal type support.

  • 0 Votes
    2 Posts
    867 Views
    SGaistS

    Hi and welcome to devnet,

    You can use a proxy model that adds the columns you want/need.

    You can keep updating the DB content and trigger the GUI update at some known interval or when a certains amount of changed happened to the database.

  • 0 Votes
    4 Posts
    3k Views
    kshegunovK

    @Nosba said:

    but how can I know when the user is editing a cell?

    I don't know, and that wasn't your original question. One thing you could try is to subclass the view and reimplement the edit() method from where you can emit a signal that notifies you when editing has started. I hope that helps.

    Kind regards.

  • 0 Votes
    10 Posts
    6k Views
    HunterMetcalfeH

    @raven-worx

    @raven-worx said:

    do you really insert columns? or rows?
    ANd do you call the signals with the correct indexes?

    Well the columns are properly updated with the correct information after the beginInsertColumns and endInsertColumns, so yes I am 100% certain the view is being updated when the model changes. I'm also certain that the sort and delete work as both functions are reflective in the view.

    yes it's not necessary to call dataChanged() with an invalid index. Rather you should call it with the index which data has cahnged obviously.

    I understand that, again this code was not written by me, I'm simply attempting to solve an issue that was discovered. Moving on from both of your points we still have yet to find a solution. The issue is with the selection of data, not the addition, subtracting or sorting thereof. I believe the issue had to do with the Update function (as a hunch) perhaps it is a mutex locking issue in the model?