Results 1 to 4 of 4

Thread: Add icon to the right in a QTreeView

  1. #1
    Join Date
    Dec 2009
    Posts
    62
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Add icon to the right in a QTreeView

    Hi

    I am using my first QTreeView with QStandardItem and I got it to work as I wanted. I have a list with names and an icon to the left like this, it is a contact list:

    (icon) Mike
    (icon) Peter
    (icon) John
    (icon) Steve

    What I want is a button aligned to the right on each row in the tree view like this:

    (icon) Mike...................(icon2)

    So when I click icon2 I will open up a screen with some more info about Mike, his phone no, adress etc. Like on the iPhone.

    I have tried to read up on the MVC but I really could use some advice to get over the first threshold since I am a bit confused. What do I need to add to my QTreeView/QStandardModel/QStandardModelItem in order to achive this.

    Thanks in advance

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Add icon to the right in a QTreeView

    I would suggest implementing custom delegate responsible for drawing and handling clicking.

  3. #3
    Join Date
    Dec 2009
    Posts
    62
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Add icon to the right in a QTreeView

    Thanks, I have started to readup on this but I wanted to try the QStandardItem approach first.

    What I did is to add some text instead of the icon to the right, like this.
    (icon) ContactName.................>>

    I did like this, adding two QStandardItem:
    QStandardItem* item = new QStandardItem( QIcon(":/gui/images/bigw_online.png"), contactId);
    item->setCheckable(true); //Use setcheckState to programatically set the checkbox
    item->setEditable(false);

    //Add the second item
    QStandardItem* item2 = new QStandardItem( QString(">")); //QStandardItems are destroyed by the model they are used in
    item2->setCheckable(false);
    item2->setEditable(false);
    item2->setTextAlignment(Qt::AlignRight);

    I could then catch the click on item2 fine, the only problem is that the > characted in item 2 is put outside of the screen so I have to scroll to see it. I tried to shut of horizontal scrolling but that did not work. I tried setSizeHint so the text in item1 did was very short but this also failed.

    So I have two QStandardItems, one with icon and text and the second only with text. How can I force them to fit on the screen so there is no horizontal scrolling.

    Any ideas or is delegates the only way to go, or would I have the same problem with them?

    Thanks alot

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Add icon to the right in a QTreeView

    I second to faldzip... use delegates...
    give time to it.. it will help in long run

Similar Threads

  1. QTreeView ICON
    By Raymond in forum Qt Programming
    Replies: 2
    Last Post: 28th October 2009, 02:43
  2. adding one icon to all items in QTreeView
    By Mystical Groovy in forum Qt Programming
    Replies: 6
    Last Post: 6th October 2009, 12:13
  3. Differentiate the icon and text in a QTreeView column
    By gmat4321 in forum Qt Programming
    Replies: 0
    Last Post: 25th February 2009, 15:38
  4. QTreeView - different icon sizes on sublevels?
    By luf in forum Qt Programming
    Replies: 3
    Last Post: 18th January 2008, 15:34
  5. How to dispay an icon in the first column of QTreeView
    By yogeshm02 in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2006, 15:51

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.