PDA

View Full Version : QTableView Row Selection



ToddAtWSU
6th December 2007, 21:51
I have just upgraded from Qt 4.1.4 to Qt 4.3.0 and am having a few bugs. I have a QTableView that holds a bunch of QVariant data. I have it set up so the user selects the whole Row when they click on a cell. This was working fine in Qt 4.1.4, but now it somewhat works in Qt 4.3.0. What happens now is when I click and drag to select multiple rows, the first row is selected correctly, but subsequent rows only highlight the first cell of the row. Some of the rows have a thin black selection line underneath some of the other cells in the selected row. However, if I pull a window to the front of the screen and then bring the window containing my QTableView back to the front, forcing a redraw, all the selected rows are highlighted correctly. I have tried calling a repaint call on the QTableView when I release the mouse button, but this did not fix the call. Does anybody have any ideas why this worked fine in Qt 4.1.4 but not now in Qt 4.3.0? My code is on a standalone Solaris and the only way I can get the code off it is to print it and retype it, which I would prefer to not do unless it is necessary. Thanks for your help!

jpn
6th December 2007, 22:05
I have just upgraded from Qt 4.1.4 to Qt 4.3.0
Just out of curiosity, why half a year old 4.3.0 now that several bug fix releases for the 4.3 series are already out?

xbase
10th December 2007, 10:08
do you use slelection model or select is on your own?

wysota
10th December 2007, 10:43
Does anybody have any ideas why this worked fine in Qt 4.1.4 but not now in Qt 4.3.0? My code is on a standalone Solaris and the only way I can get the code off it is to print it and retype it, which I would prefer to not do unless it is necessary. Thanks for your help!

I'd suggest upgrading to 4.3.3 first and checking if the error persists. Then (if it does) please tell us whether you modify the model during the life of the application. You can't select items which return invalid QVariant values for DisplayRole - maybe that's your case. If you modify the model (returning proper data for those items), it could "repair" the selection.

ToddAtWSU
11th December 2007, 15:03
I cannot upgrade to 4.3.3 right now due to requirements. I was lucky to get to move from 4.1.4 to 4.3.0. I am pushing to get approval to upgrade to 4.3.3, but I don't have it yet. It doesn't make sense to me why it worked great in 4.1.4 but not now in 4.3.0. Why would something break that was working.

I don't manaully set the selection. I just told it to select the entire row when a cell was clicked on. I do emit a signal on the mouseRelease event so the parent holding the QTableView can do further calculations when a row is selected, but nothing that influences the table. The table is not being modified in anyway when a selection occurs. To me the confusing part is the first row I select updates correctly, highlighting the whole row, but subsequent rows do not.

I doubt I have added any substance to my first post besides stating why I am not at 4.3.3 yet, but I am sorry I am not with 4.3.3 but when higher beings set the requirements, it is hard to get them to allow changes sometimes. So until then this is what I am stuck with. Thanks again for your help!

wysota
11th December 2007, 15:29
Could you post a minimal compilable example reproducing the problem? We'll try to run it on newer versions of Qt to see whether the problem was resolved.

ToddAtWSU
11th December 2007, 18:39
I can try to come up with one but it could take a bit as I have a QVariantDataModel that stores my data. And then I call the setModel on this to store the data. However, this appears to be working fine since it has no influence on the QTableView selection at all.

But in the meantime, can you explain why calling repaint( ) or update( ) on the table or dialog doesn't work, but bringing a secondary window to the front over the window with the table, forcing the table to redraw, causes the rows to be highlighted correctly? Thanks!

wysota
11th December 2007, 19:49
QVariantDataModel? Does it differ from QStandardItemModel?

ToddAtWSU
12th December 2007, 21:27
Well I figured out my problem. I originally had the table displaying 6 columns of data and had the selection set to NoSelection. After I would hit a load button, I would add 2 more columns of data to the table and then allow MultiSelection once the data was loaded. I would reset the table headers to add on these last 2 columns headers and this was where my problem came in at. I did not have the "beginInsertColumns" and "endInsertColumns" calls being made around setting the titles and adding the columns. So my selection thought I was trying to select 8 columns and the table only had 6 columns. Once I fixed the problem to make sure all 8 columns were showing, the selection fixed itself because there were a proper number of columns. Thanks for your help and I guess the "beginInsert" calls are more strict in Qt 4.3.0 than in Qt 4.1.4. Thanks again though!