Results 1 to 6 of 6

Thread: Suggested course of action for drawing an image across a QTreeView

  1. #1
    Join Date
    Sep 2007
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Suggested course of action for drawing an image across a QTreeView

    Hello,

    I'm writing a Qt for embedded Linux application (version 4.5). This is a single purpose embedded application, so non-portable solutions are acceptable. I have a QTreeView, populated by a QStandardItemModel, which is in turn populated by a database. *Some* of these records have images associated with them (those images are PNG files, stored as binary blobs in the db). Because the font I'm using with the QTreeView is somewhat large, each row is also large (this is a touchscreen application, so everything is chunky). Here's how my QTreeview looks at the moment:

    +--+-------------------
    | #| description
    +--+-------------------
    | #| description
    +--+-------------------
    | #| description
    +--+-------------------

    What I'd like is for those rows and *only* those rows that have images associated with them to become thicker to accommodate the 100 * 100 pixels PNG image:

    +--+-------------------
    | #| description
    +--+-------------------
    | |
    | #| [pic] description
    | |
    +--+-------------------
    | #| description
    +--+-------------------

    Can you suggest an approach to:

    1. Construct a QImage, or QPixmap, or whatever is appropriate using the raw PNG file from the database (I'll have a char pointer to a buffer and an integer that holds the size of the file in bytes).

    2. Thicken, and then draw the PNG file onto those rows that have an image to display, as illustrated.

    Your help is greatly appreciated,

    Regards,
    Sternocera

  2. #2
    Join Date
    Sep 2007
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Suggested course of action for drawing an image across a QTreeView

    I was successful with the following approach:

    Qt Code:
    1. QStandardItem item2 = new QStandardItem(...);
    2. QImage glyph(QImage::fromData(pBuffer, glyph_bin_string.size(), "PNG" ));
    3. if(!glyph.isNull())
    4. {
    5. QIcon description_icon(QPixmap::fromImage(glyph));
    6. static const QSize hint(100, 100);
    7. description_icon.actualSize(hint);
    8. item2->setSizeHint(hint);
    9. item2->setIcon(description_icon);
    10. }
    To copy to clipboard, switch view to plain text mode 

    Now, I have one small problem: My QIcon is highlighted when active/selected; It has a blue hue. I would prefer it if it didn't have any blue hue while highlighted/select.

    Is that possible?

    Regards,
    Sternocera

  3. #3
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suggested course of action for drawing an image across a QTreeView

    Have you tried with styles ?

    Take a look at this

  4. #4
    Join Date
    Sep 2007
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Suggested course of action for drawing an image across a QTreeView

    jpujolf,

    That's an interesting idea. However, it isn't clear if its possible to customise the appearance of a QTreeView's icon through stylesheets. I tried this:

    app.setStyleSheet("QTreeView::icon:selected {"
    "border-color: darkblue;"
    "background: rgba(150, 150, 150, 150);"
    "}");

    This has the effect of making the header's font appear smaller, but that's all. It didn't cause a runtime error, or for anything to be printed to std:cerr, so I guess it was parsed successfully.

    The Qt style sheets example has examples for QTreeView, but nothing that directly relates to icons: http://doc.trolltech.com/4.3/stylesh...zing-qtreeview.

    How can I customise the appearance of the QIcon using stylesheets, removing the blue hue as described? Is it possible at all?

    Regards,
    Sternocera

  5. #5
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Suggested course of action for drawing an image across a QTreeView

    Quote Originally Posted by sternocera View Post
    How can I customise the appearance of the QIcon using stylesheets, removing the blue hue as described? Is it possible at all?
    I'm not sure it's possible, but as you could read in the post I was searching the way to enhance the selected cell.

    With this style :

    Qt Code:
    1. QTreeView::item:focus
    2. {
    3. background-color:rgba(150, 150, 150, 150);
    4. color:darkblue;"
    5. }
    To copy to clipboard, switch view to plain text mode 

    your selected cells may look as you wanted. Tell me if it works...

  6. #6
    Join Date
    Sep 2007
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Suggested course of action for drawing an image across a QTreeView

    jpujolf,

    No, I'm afraid that doesn't make any noticeable difference, except that it changes the header font size as before,

    Regards,
    Sternocera

Similar Threads

  1. QTreeView default drag action
    By onamatic in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2010, 07:37
  2. Problems with drawing image in paintEvent of QTreeView
    By Tito Serenti in forum Qt Programming
    Replies: 7
    Last Post: 24th December 2008, 23:25
  3. background image in QTreeView
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 11th January 2007, 06:25

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.