Qt Commercial Support Weekly #20: Visualizing the Logical
In QHeaderView there is admittedly a confusing concept of referring to the different header sections, they can be referred to by their logical index or by their visual index. And then when you start trying to use the functions to go from one to the other then it can begin to get even worse. So this will hopefully go some way to clearing this up for those who need to understand how it all works together.
First of all, to set the scene, we will have five sections in the QHeaderView and to make it easy to follow they will be in alphabetical order, i.e. A to E. So our headerview starts off looking like this:
The visual index is referring to where it is currently placed on the headerview, and the logical index is referring to the order that the sections were added which was in the order A to E. So the following function calls will give the following results:
So far it is fairly straightforward, so let's say we want to move A to be after C in the order by calling moveSection(0, 2), this is done using the visual index for the sections so for this case it is going to be clear what happens. Now we end up with everything looking like:
and calling the same functions as before gives the following results:
And now finally lets move E to the beginning, remember this is using visual indexes so we need to call moveSection(4, 0) as it doesn't matter what order it was added in, just the order that it appears on the headerview at this point in time. Now we have the following:
and calling the functions give us:
So hopefully this goes some way into clearing up how the different functions work with relation to visual indexes and logical indexes. The key thing to remember is that when you call logicalIndex() then you pass in the visual index you want the logical index for and when you call visualIndex() you pass in the logical index you want the visual index for. It is certainly easier said than done :)
Until next time, happy coding :)
Subscribe to our newsletter
Try Qt 6.4 Now!
Download the latest release here: www.qt.io/download.
Qt 6 is the productivity platform for the future, with next-gen 2D & 3D UX and limitless scalability.
Explore Qt World
Check our Qt demos and case studies in the virtual Qt World
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don't want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu