Summary

PyQt's built-in view widgets, and the graphics view widgets, between them provide considerable scope for visualizing datasets. But when our requirements don't really match what these classes provide, we can always create our own custom views and present our data exactly how we like.

Since a custom view could potentially be showing a portion of a very large dataset, it is usually best to optimize the paint event handler to retrieve and display only those data items that are actually visible. If scrollbars are going to be required, we could require that users of our view class use a QScrollArea, or create a composite widget with a couple of QScrollBars, or create a widget that inherits QAbstractScrollArea. The first of these approaches adds only a few lines to the user's code, and makes implementing the view much easier.

Using generic delegates with data-type-specific column delegates makes it easy to create ad hoc "custom" delegates for views. Column delegates are easy to create and can cut down on code duplication since we need only one column delegate for each data type we want to work with. The generic delegate approach is ideal for datasets where each column's data holds values of a single data type, such as database tables.

Creating tree models can be difficult because we have to think in terms of parents and children, where the children may also be parents, and so on recursively to an arbitrary level of depth. This just isn't as easy as the thinking in terms of rows and columns necessary for tree and column models. Although the tree of table model presented in this chapter is a specific example, some of the methods that provide its tree functionality, such as index(), parent(), and nodeFromIndex(), should be able to be used "as is" or with little adaptation, and other methods, such as addRecord(), should also prove to be adaptable.

Was this article helpful?

0 0
Tube Jacker

Tube Jacker

Download Tube Jacker And Discover Everything You Need To Know About Jacking Unlimited Traffic From The Video Giant. The drop dead easy way to create winning video campaigns that will FLOOD your website with unstoppable FREE traffic, all on complete and total autopilot. How to exploit a sneaky method of boosting exposure and getting your videos to the top of Google within 72 hours, guaranteed.

Get My Free Ebook


Post a comment