Results 1 to 17 of 17

Thread: QListWidget...what's wrong

  1. #1
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy QListWidget...what's wrong

    i wish to display the file icon of listview.cpp in the QListView Widget...but am just getting the text passed to the constructor i.e. "nupul"

    What is wrong?

    Qt Code:
    1. #include <QApplication>
    2. #include <QListWidget>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6.  
    7. QApplication app(argc, argv);
    8.  
    9. l->setViewMode(QListView::IconMode);
    10.  
    11. QIcon icon("/Qt/4.1.0/project/listview/listview.cpp");
    12. QListWidgetItem *item=new QListWidgetItem(icon, "nupul",l,0);
    13.  
    14. l->addItem(item);
    15.  
    16. l->show();
    17.  
    18. return app.exec();
    19.  
    20. }
    To copy to clipboard, switch view to plain text mode 

    Thanks

    Nupul

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget...what's wrong

    "/Qt/4.1.0/project/listview/listview.cpp"
    is this a valid path of an icon? If nothing changed, files with "cpp" extension tend to be c++ source files and not icons. And it's doubtfull that your Qt directory is a direct child of root of the directory tree (unless you have a weird installation).

  3. #3
    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: QListWidget...what's wrong

    I suppose you are looking for something like this:
    Qt Code:
    1. QFileIconProvider iconProvider;
    2. QFileInfo fileInfo("...listview.cpp");
    3. QIcon icon = iconProvider.icon(fileInfo);
    4. QListWidgetItem *item=new QListWidgetItem(icon, "nupul",l,0);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. #4
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Unhappy Re: QListWidget...what's wrong

    Well Wysota, this is what the Qt4.1 doc has to say

    QIcon::QIcon ( const QString & fileName )
    Constructs an icon from the file with the given fileName. The file will be loaded on demand. If the file does not exist or is of an unknown format, the icon becomes a null icon.
    If fileName contains a relative path (e.g. the filename only) the relevant file must be found relative to the runtime working directory.
    The file name can be either refer to an actual file on disk or to one of the application's embedded resources. See the Resource System overview for details on how to embed images and other resource files in the application's executable.
    Which implies that an icon name needn't be passed...

    as for the path on my system is concerned....Qt is installed in windows and thus the strange path....I chose it

    p.s. I took your suggestion and also gave a path to a .ico file....No luck


    Nupul

  5. #5
    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: QListWidget...what's wrong

    The file must be a supported image format.
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget...what's wrong

    Quote Originally Posted by nupul
    Which implies that an icon name needn't be passed...
    "fileName" is not the name of a file for which the icon is to be generated but a name of a file which contains an image that is to be loaded as an icon.

    as for the path on my system is concerned....Qt is installed in windows and thus the strange path....I chose it
    Shouldn't it start with a drive letter?

    p.s. I took your suggestion and also gave a path to a .ico file....No luck
    Qt doesn't handle .ico files (see the link in the previous post).

  7. #7
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QListWidget...what's wrong

    Firstly Thanks for the replies...but I am still confused



    As per the qt doc:
    The simplest way to create a Q3IconView is to create a Q3IconView object and create some Q3IconViewItems with the Q3IconView as their parent, set the icon view's geometry and show it. For example:


    Q3IconView *iv = new Q3IconView(this);
    QDir dir(path, "*.xpm");

    for (uint i = 0; i < dir.count(); i++)
    {
    (void) new Q3IconViewItem(iv, dir[i], QPixmap(path + dir[i]));
    }

    iv->resize(600, 400);
    iv->show();
    W.r.t to the above code could anyone pls explain the Constructor of Qdir as given...Is it:

    Qt Code:
    1. QDir ( const QString & path, const QString & nameFilter, SortFlags sort = SortFlags( Name | IgnoreCase ), Filters filters = AllEntries )
    To copy to clipboard, switch view to plain text mode 

    ...where the sortflags and filters are optional??

    Also what is this code doing different from what I put forth before??

    I intend to display the contents of "/homes/nupul/desktop" folder on the ListWidget exactly how my linux (SuSE 10) system would show it on the Desktop...with all the associated icons for the respective files.

    Do i need to custom create my icons w.r.t the allowable Image formats supported by Qt4? Can't I use the Icons provided by the system? <-- how should i achieve the latter?

    The QListWidgetItem Constructor is given as:

    Qt Code:
    1. QListWidgetItem ( const QIcon & icon, const QString & text, QListWidget * parent = 0, int type = Type )
    To copy to clipboard, switch view to plain text mode 

    what is the 'text' for? it's the text to be displayed below the icon, right? I want the file name to appear below the Icon...so what should I do?

    what is the last int type=Type for and how does it affect the code???


    Also could you please elaborate (in simple terms and NOT doc language) on the Use of QIconEngine...when/why should one use it?

    Thanks

    Nupul

  8. #8
    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: QListWidget...what's wrong

    So are you using a QListWidget or Q3IconView?

    I would suggest you to check out QDirModel+(QTreeView/QListView) combination.
    With those you can very easily show contents of the file system.

    For system specific icons you need to provide your own QFileIconProvider.
    QFileIconProvider is a simple class which (as the name suggests) provides icons.
    The default QFileIconProvider provided by Qt handles only a few types of icons (Computer, Desktop, Trashcan, Network, Drive, Folder, File). By subclassing QFileIconProvider you can supply system specific icons for QDirModel.
    J-P Nurmi

  9. #9
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Red face Re: QListWidget...what's wrong

    well i will be using Qlistwidget only....QIconView was just an example i stumbled on while sifting through the doc...

    I wish to use the System Icons only i.e those by KDE 3.2 on my SuSE 10....and wish to display them as is in Qt - (as i mentioned earlier). Is There NO way to do this in Qt without tinkering around with the QFileIconProvider....

    ...hope you understand what I am trying to say....

    e.g say i wish to design Konqueror or a windows explorer type application....I want the contents of a folder to be displayed on the right listwidget with the same icons as the system uses. Shouldn't Qt be able to do this Directly??

    Also in the book C++ programming with Qt3, there is a find-file-dialog example....in which the listview at the bottom displays the files just as a normal Find dialog in windows/X would....i.e. the corresponding file icons are shown....but there is no mention of it's implementation...



    Thanks

  10. #10
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget...what's wrong

    If you want the system icons try to get the standard pixamp of the current style with:
    Qt Code:
    1. style -> standardPixmap(QStyle::SP_DirOpenIcon)
    To copy to clipboard, switch view to plain text mode 
    for example it will return the standar pixamp for the folder opened icon. Take a look at all the other standarPixamps defined in QStyle class. Then you only have to set this pixamp to the icon you want.

  11. #11
    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: QListWidget...what's wrong

    File icon bindings are system specific.
    In windows you would probably have to use SHGetFileInfo.
    Somewhy I have a strong feeling that on X11, this even differs on different desktops.
    J-P Nurmi

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget...what's wrong

    If you wish to bind your application tightly with KDE, you should consider switching to KDE-based development. Then you'll be able to use icons provided by KDE directly. But this will make your application unusable on non-kde systems. And also remember that KDE4 is still in early development stage, so you might need to switch to Qt3/KDE3.

  13. #13
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: QListWidget...what's wrong

    Well let me tell you all what i intend to do....I am creating a desktop manager for Linux (SuSE 9/10) as a project and am using Qt for it's development. If Wysota, jpn will try and recollect most of my doubts are indirectly/directly related to components related to the desktop manager viz. panel, toolbars, etc..

    Now the thing is this....I will be displaying the icons of /homes/<user name/desktop
    on the desktop....and I'll be using QListWidget for the same. Now what you need to tell me is how should I display the Icons depicting various files

    1. Should I subclass QFileIconProvider??
    --then you need to give me some hints on how to do it, as I never thought that I'd need to custom design my own Icons

    or

    2. Is it possible to display the Icons provided by the underlying system?
    --I will need some help here too

    If at all i design my own icons...pls tell me the preferable file format to use for icon images and how do I make sure that I cover all the icons in the system

    If i am not wrong there is a folder in KDE (can't recollect at the moment though) where the icon images are stored...how can I make use of this??

    Thanks

    Nupul

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget...what's wrong

    You can subclass QFileIconProvider which will use /usr/share/icons (or simmilar) to fetch and provide icons.

  15. #15
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QListWidget...what's wrong

    It seems i'll be taking a "hybrid" of the 2 ways of using icons, i mentioned before. But there is still one thing....

    I want QListWidget to open the corresponding folder/file when the user double/single clicks...It didn't work by default ( or was it supposed to?!?). So do i need to add signals and slots for it or what....???

    Thanks

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget...what's wrong

    You're not using QDirModel, right? So how do you expect the list of icons open some directory by itself? You have to connect signals you want to slots where you'll implement that functionality yourself. Alternatively you can use QDirModel and have the behaviour out of the box

  17. #17
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking Re: QListWidget...what's wrong

    Phew!!!.........

    Firstly a BIG thanks to all of you to help me in this issue...
    After receiving clarification/guidance from you guys, I did a more extensive study from the Qt4 doc (er..with more concentration) and finally understood what all were trying to make me understand

    Concluding from the discussion, this is what I'll be doing :

    1. Will be using the QListView+QDirModel structure for displaying the icons on 'my' desktop.

    2. Will be subclassing the QFileIconProvider and providing for my own icons (actually got them from KDE distro....they aren't used by any of the distros I know...and they are open source too ...saves me the pain of custom developing my own icons )

    3. Will clarify doubts @ qtcentre as and when they arise!!!

    Thanks!

    Nupul.

Similar Threads

  1. Segmentation Faul using addItem (QListWidget)
    By gnusar in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2008, 09:27
  2. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  3. Replies: 13
    Last Post: 15th December 2006, 11:52
  4. keypress while editing an item in QListWidget
    By Beluvius in forum Qt Programming
    Replies: 3
    Last Post: 4th April 2006, 09:56
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.