Results 1 to 4 of 4

Thread: Sub classing QListWidgetItem

  1. #1
    Join Date
    Nov 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Post Sub classing QListWidgetItem

    Hello,

    I have small problem and I think its the last one to finish this project. I have I want to create Table view that contain items ( QListWidgetItem). Each item should contain name, image and pointer to hold object from type ( QSqlQueryModel).

    I have to problem by item name and image. The only problem is to add to that Item a pointer can hold QSqlQueryModelobject. I try to subclass QListWidgetItemand add the pointer but did not work

    can anyone help me in this ?
    thanks

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Sub classing QListWidgetItem

    Why don't you use the QSqlQueryModel with QListView?
    J-P Nurmi

  3. #3
    Join Date
    Nov 2008
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Sub classing QListWidgetItem

    I don't want to used QListView because I'm not good with Model Based , But this is not the problem.

    I create QListWidget, and I use it to hold Items. Each Item has name and icon. Now I want the item to hold QSqlQueryModel .

    This list will be like history of all SQL quires, so when the user do a query it will be saved in that list as QSqlQueryModel object, When the user click on the icon , the query result will be read loaded in the box of result. so each time the user choose query from history , I just need to take the QSqlQueryModel object which saved in the items of the list and pass it to the table view which show the result.

    because of that i want the item of the list which is from type QListWidgetItem to have ability to carry object from type QSqlQueryModel , and this is my problem

  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

    Angry Re: Sub classing QListWidgetItem

    A simpler approach to your problem would be as follows -
    For the listWidgetItem, use setData to store the result in your defined role, say RESULT_ROLE.
    Now use a custom delegate and override the drawDisplay as follows -
    Qt Code:
    1. MyDelegate::drawDisplay(......)
    2. {
    3. QString result = text; // text is the argument string to draw
    4. if(option.state & Qt::Selected) // if item is selected...
    5. result = index.data(RESULT_ROLE);
    6.  
    7. QItemDelegate::drawDisplay(result....); // use result instead of text
    8. }
    To copy to clipboard, switch view to plain text mode 
    Hope this works for you

Similar Threads

  1. QListWidgetItem in Drag n' drop
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 3rd April 2009, 14:43
  2. Replies: 1
    Last Post: 12th October 2008, 19:02
  3. Check Box problem
    By Seema Rao in forum Qt Programming
    Replies: 6
    Last Post: 30th November 2007, 19:32
  4. Problems subclassing QListWidgetItem
    By Morea in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2006, 09:27
  5. QListWidget add QListWidgetItem
    By fellobo in forum Qt Programming
    Replies: 3
    Last Post: 20th February 2006, 19:37

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
  •  
Qt is a trademark of The Qt Company.