Results 1 to 3 of 3

Thread: how change the QListBox item position by pixel

  1. #1

    Exclamation 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] [/IMG][IMG]C:\Documents and Settings\cnh50285\My Documents\My Pictures\test.gif[/IMG]

  2. #2
    Join Date
    Jan 2006
    Posts
    25
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

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

    Qt Code:
    1. myListView::SlotChangeHeight()
    2. {
    3. if (currentItem())
    4. {
    5. currentItem()->setHeight(44);
    6. }
    7. }
    8.  
    9.  
    10. ...
    11. // in constructor myListView:
    12. connect(this, SIGNAL(selectionChanged()), this, SLOT(SlotSelectionChanged()) );
    To copy to clipboard, switch view to plain text mode 

    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);"
    Qt Code:
    1. if (previous != 0) {
    2. previous->setHeight(22);
    3. }
    4. previous = currentItem();
    To copy to clipboard, switch view to plain text mode 

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

  3. #3

    Default 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]

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.