PDA

View Full Version : Positioning a List Widget delegate so it is all visible



maird
22nd October 2007, 02:32
Can anyone tell me how to calculate the position to place a QListWidget at in a QTableView so that no part of the list is clipped by being outside of the view rectangle. I tried the obvious arithmetic and still get the list clipped at the bottom of the view. For example, if the parent geometry is 10, 10, 210, 210 (200 pixels square) and the list size is 50, 100 then positioning it at 10, 109 should ensure it is all visible. That's not what I find.

Attached should be a small project that illustrates the problem in code. It is an Eclipse project and I used Qt 4.3.2 on a x86_64 Linux with x.org 7.2. Anyone trying it will probably have to modify paths in the Makefiles but it should build outside of Eclipse.

The application has a large table view with a model. Two columns (5 and 6 on screen) have delegate editors that provide a list widget. The actual editor widget is a class derived from QListWidget that seeks to ensure that the list rectangle is completely contained inside its parent - see CellListWidget in Delegates*

Start the app and double click on anything in Col 5 or Col 6 to see the editor list. If you pick a cell near enough to the bottom of the view then the list will re-position itself to be contained within the parent. The Col 5 delegate will position its top at y = 0 in the parent. The Col 6 delegate will position its bottom at the bottom of the parent. In the bottom case myParent()->geometry().bottom() is used as the reference position.

The problem is that the case where the list tries to position its bottom at the bottom of the view then it actually extends below the bottom of the view and gets clipped. If you build with debug you should see the rectangles and arithmetic as qDebug() output on the console.

The error is about 30 pixels on my host. Interestingly the top aligned case doesn't actually show at the top of the table view, only at the top of the first non-header row, even though the top y value is zero for the list widget. The height of the header row isn't 30 on my host, it's about 22. It's not the horizontal scrollbar that causes it, re-size the window so that there is no horizontal scrollbar and it still happens. I don't want to add an arbitrary - 30 to my arithmetic so I'd appreciate anyone else's observations with the attached project and comments on what I'm missing.

maird
22nd October 2007, 03:04
Never mind. I spotted the problem in my own debug output. I was interpreting all child co-ordinates as having an outside origin. So, from my example above. The 10, 210, 10, 210 window has a size of 200, 200. The vertical place to position a 50, 100 item in it so that it touches the bottom isn't x, 110 it's obviously x, 100. The change to the project I posted is:

*** Delegates.cpp 2007-10-21 19:00:37.000000000 -0600
--- Delegates.cpp 2007-10-21 19:00:44.000000000 -0600
59c59
< myrc.moveTop(prc.bottom() - myrc.height());
---
> myrc.moveTop(prc.height() - myrc.height());