PDA

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



roy_skyx
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
{
.......
protected:
virtual int height (const QListBox*) const {

if (isCurrent())
return 44;
else
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

edb
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:




myListView::SlotChangeHeight()
{
if (currentItem())
{
currentItem()->setHeight(44);
}
}


...
// 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->setHeight(22);
}
previous = currentItem();


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

roy_skyx
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

thanks!


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