how change the QListBox item position by pixel
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.
[IMG]:D [/IMG][IMG]C:\Documents and Settings\cnh50285\My Documents\My Pictures\test.gif[/IMG]
Re: how change the QListBox item position by pixel
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:
Code:
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);"
Code:
if (previous != 0) {
previous->setHeight(22);
}
previous = currentItem();
Don't forget to set previous to 0 in the constructor of myListview!
Re: how change the QListBox item position by pixel
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?
[IMG]C:\Documents and Settings\cnh50285\My Documents\My Pictures\test.gif[/IMG]