Results 1 to 14 of 14

Thread: :( Problems with QTreeWidgetItem icons

  1. #1
    Join Date
    Jan 2007
    Posts
    13
    Qt products
    Qt4

    Default :( Problems with QTreeWidgetItem icons

    Hi all,

    If I try to add no square shaped QIcon object to QTreeWidgetItem it doesn't displayed on item. Who is know the workaround for this. Please help me.

    Thanks in advance,
    --davit

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

    Default Re: :( Problems with QTreeWidgetItem icons

    The shape doesn't matter. Can we see your code?

  3. #3
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: :( Problems with QTreeWidgetItem icons

    I confirm, I just tried to display a 64x20 icon in my treewidget...and it doesn't appear!

    It works in Qt Designer though..

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

    Default Re: :( Problems with QTreeWidgetItem icons

    My guess is that probably you provided a relative path to the image which is incorrect runtime and the pixmap can't be created. Could you please show us the code?

  5. #5
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: :( Problems with QTreeWidgetItem icons

    Well, in my application, I use a resource file.
    You can find in it (amongst others), a squared PNG image (64x64), that I always use as an icon for my tree items.

    I simply resized it to 64x20 with mogrify, recompiled, and then...no more icons...

    I checked the tracker, and I didn't find something relevant...

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: :( Problems with QTreeWidgetItem icons

    Perhaps the saved file cannot be interpreted by Qt. ( not standard PNG ).
    I'm just saying...

  7. #7
    Join Date
    Jan 2006
    Location
    Paris, France
    Posts
    227
    Thanks
    3
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: :( Problems with QTreeWidgetItem icons

    I thought of that first, but since it's correctly displayed in QtDesigner, I think that's some damn good PNG

    Really annoying if it's a bug...there may be an easy workaround by making square pixmaps with transparent zones.

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

    Default Re: :( Problems with QTreeWidgetItem icons

    Could you just please show some code? It's not a bug, I assure you. I have used non-rectangular icons (define "non-rectangular" anyway... every image is rectangular) just fine many times.

  9. #9
    Join Date
    Jan 2007
    Posts
    13
    Qt products
    Qt4

    Default Re: :( Problems with QTreeWidgetItem icons

    Hi wysota,

    The code is simple. I have implemented my own tree_widget_item class which is inherited from QTreeWidgetItem. The constructor is following:

    Qt Code:
    1. tree_widget_item(QTreeWidget* t, const QString& s, const QPixmap& p)
    2. {
    3. setIcon(QIcon(p));
    4. }
    To copy to clipboard, switch view to plain text mode 
    p is correct pixmap, because if I use it for giving icon to comboBox it displays correctly.

    Note: I didn't said that icon has no rectangular shape, I said that icon has no square shape.
    By saying icon in this case I mean QPixmap object, from which I'm trying to create QIcon.
    For rectangular Icons it works unstable (in some cases it displays, in other ones not).

    Thanks,
    --davit

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

    Default Re: :( Problems with QTreeWidgetItem icons

    Could you provide a little more code? Something that compiles, maybe? If you're able to reproduce the problem on a small example, it could help to solve the issue.

    This seems to work fine for me (with a non-square pixmap).

    Qt Code:
    1. #include <QApplication>
    2. #include <QTreeWidget>
    3. #include <QTreeWidgetItem>
    4. #include <QtDebug>
    5.  
    6. int main(int argc, char **argv){
    7. QApplication app(argc, argv);
    8. wgt.setColumnCount(1);
    9. QTreeWidgetItem *item = new QTreeWidgetItem(&wgt);
    10. QPixmap px("someimage.jpg");
    11. qDebug() << px.size();
    12. item->setIcon(0, QIcon(px));
    13. wgt.show();
    14. return app.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 16th April 2007 at 17:04.

  11. #11
    Join Date
    Jan 2007
    Posts
    13
    Qt products
    Qt4

    Default Re: :( Problems with QTreeWidgetItem icons

    Hi wysota.

    Your code doesn't work for attached .xpm file (icons doesn't displayed on treeWidget items).

    Note: I'm using Qt4.2.2 on RHEL3.0.

    Thanks,
    --davit
    Last edited by davit; 18th April 2007 at 11:33.

  12. #12
    Join Date
    Jan 2007
    Posts
    13
    Qt products
    Qt4

    Default Re: :( Problems with QTreeWidgetItem icons

    Sorry I can't attach my file. So I'll copy the content to here.

    Qt Code:
    1. /* XPM */
    2. static char *dummy[]={
    3. "150 1 1 1",
    4. ". c #000000",
    5. ".
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: :( Problems with QTreeWidgetItem icons

    It works just fine. It is just being scaled down so that it can fit into the item. Try a 25x10 image or change the icon size.

  14. #14
    Join Date
    Jan 2007
    Posts
    13
    Qt products
    Qt4

    Default Re: :( Problems with QTreeWidgetItem icons

    Thanks guys for replays.
    I have found solution. It seems QTreeWidget requires to set to icon that size which has QPixmap object.
    So, we need to do following:

    Qt Code:
    1. QPixmap p("somefile.xpm");
    2. t->setIconSize(p.size());
    3. item->setIcon(QIcon(p));
    To copy to clipboard, switch view to plain text mode 

    Best regards,
    --davit

Similar Threads

  1. QTreeWidgetItem ?
    By allensr in forum Qt Programming
    Replies: 5
    Last Post: 3rd January 2007, 17:51
  2. Suppressing menu icons on the Mac
    By Brandybuck in forum Qt Programming
    Replies: 2
    Last Post: 7th November 2006, 19:00
  3. QTreeWidgetItem swap or move up one level problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 24th September 2006, 18:34
  4. Facing problem with tool bar icons
    By jnana in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 08:37
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 16:30

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.