开发者

How to show only 30 rows and hide the remaining rows of QTableWidget

I'm having a QTableWidget with 10,000 records. I need to show only 30 rows at a time and hide the remaining rows. While dragining/clicking vertical scrol开发者_运维百科lbar it should show corresponding rows and hide the other rows.

ie, if one clicks on upper scroll button it should show one more upper item and hide one lower item and vice versa. It should happen while scrolling as well.

Can anyone help me in doing this?


I think you can trap the events of up/down buttons as Nicholas said, for the tracking of slider/scroll bar u need use 'setTracking(true)'followed by the handling of signal either 'valueChanged(int)' or 'sliderMoved(int)'.

Thanks, Pradeep


Qt unfortunately won't make this easy for you, there is ways and means of doing it however. Depending on how you're populating your widget I'd recommend setting it up so you initially populate your 30 rows, you then need to trap the signals coming from the scroll buttons being clicked and tell the table widget to remove the upper/lower item and add the next one, there's trade off's to this method, but it'll make it easier than trying to maintain a large list of hidden rows.


I don't know if explicitly showing/hiding things is the way you want to go. Instead, take a look at Qt's model and view classes. If you are using a database, have a look at QSqlTableModel, which should handle these things for you. Otherwise, have a look at the Model-View programming document, their related examples, and especially the portion about optimizing for performance (although in a model, 10,000 records isn't really all that many for most uses).


There is a way to change table scrolling from pixels to items. In Designer Property Editor for the table, in the QAbstractItemView section, there is a VerticalScrollMode selection. This can either be ScrollPerPixel or what you probably want, ScrollPerItem.

That may change the behavior of the signal from pixels to items which would make your calculations easier.

I'm using 4.4.3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜