View Full Version : how change the QListBox item position by pixel

19th January 2006, 10:32
I have a myqlistbox that is a subclass of QListBox, and a new qlistboxitem class which is a subclass of QListBoxItem.
class newListBoxItem : public QListBoxItem
virtual int height (const QListBox*) const {

if (isCurrent())
return 44;
return 22;

when I creat a new myqlistbox , the item which is highlight item can be twice height . if you move the highlight item ,the new highlight will become twice height, and the old hightlight item will become normal height. but the new highlight item at same position. I want the new highlight move up 22 pixels becauce the old highlight give the 22 pixels.
how can i move myqlistbox item which become twice height when it was highlight.
:D C:\Documents and Settings\cnh50285\My Documents\My Pictures\test.gif

19th January 2006, 14:07
If I understand correctly, you want to make the highlighted items twice as big as the other. This is how I would work:

In your QListView ( eg myListView : Qlistview) create a Slot that sets the height of the highlighted item and connect this slot to the:

if (currentItem())

// in constructor myListView:
connect(this, SIGNAL(selectionChanged()), this, SLOT(SlotSelectionChanged()) );

You need to keep track of the previous current Item in order to set it back to size 22.
So create a member QListViewITem * previous (or one of your own type...) and add the following lines just after" currentItem()->setHeight(44);"

if (previous != 0) {
previous = currentItem();

Don't forget to set previous to 0 in the constructor of myListview!

20th January 2006, 02:34
yes, you are right. I just want to make the highlighted items twice as big as the other. But i new a QListBox, not a QListView. Thoug both class are subclass is QScrollView.

I will test the QListView


how can I post the picture there?
C:\Documents and Settings\cnh50285\My Documents\My Pictures\test.gif