PDA

View Full Version : QTableView Problem



Eduardo Huerta
4th December 2019, 04:51
When I pass the cursor over a table using QTableView, a signal is emitted that invokes the rowCount () function of the QAbstractTableModel, even when I click on a cell, the data () function of the QAbstractTableModel is invoked, how can I disconnect the cursor signal when I am on a cell or click. I am confused that the rowCount () and data () functions are not slot functions.
Thanks for help me.

d_stranz
4th December 2019, 17:07
I am confused that the rowCount () and data () functions are not slot functions.

These can't be slots. They return a value to the caller (an int and a QVariant, respectively). Slots are void methods that can only "return" a value if they are passed a pointer or non-const reference as an argument.

If your table cells are editable, then clicking on a cell will invoke the model's data() method to retrieve the value for the EditRole. If you are moving the mouse slowly enough, then data() could also be invoked without a click to retrieve the values for the StatusTipRole, ToolTipRole, or WhatsThisRole.

If you are moving the mouse normally, then there should not be any calls into the model. Run your code in the debugger, set a breakppoint on rowCount(), and find out how it is being called by looking at the stack trace.

ChristianEhrlicher
5th December 2019, 05:50
If you are moving the mouse normally, then there should not be any calls into the model

They are (depending on the style) since the current item is highlighted which triggers a redraw.

d_stranz
5th December 2019, 16:58
They are (depending on the style) since the current item is highlighted which triggers a redraw.

Even when mouse tracking is disabled? That seems like a huge overhead - surely only the item under the cursor is the only one which must be redrawn, not the entire table.

ChristianEhrlicher
5th December 2019, 17:42
Even when mouse tracking is disabled? That seems like a huge overhead - surely only the item under the cursor is the only one which must be redrawn, not the entire table.

As I said - it depends on the style, fusion and breeze do highlight the current cell under the cursor. I'm pretty sure that not the whole table is redrawn.

Eduardo Huerta
5th December 2019, 19:04
Even when mouse tracking is disabled? That seems like a huge overhead - surely only the item under the cursor is the only one which must be redrawn, not the entire table.
Hi,
How do I disable mouse tracking on the table?
Best regards

Added after 14 minutes:

Hi,
I have cell highlighting disabled.
tableView->setSelectionMode(QAbstractItemView::NoSelection);

Even so when the cursor is over a cell, the rowCount () function is activated, which is what I want to avoid. And when I press with the mouse the cell activates the data () function that I also want to avoid. On the other hand I just redraw the pressed cell.

best regards

ChristianEhrlicher
5th December 2019, 19:29
It has nothing to do with the selection, it's the hovered item.

You can't disable this behavior except that you can use a style which doesn't do a styling for hovered items. Apart from this I don't see why this should be disabled at all.