PDA

View Full Version : Suggested course of action for drawing an image across a QTreeView



sternocera
29th March 2009, 22:32
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

sternocera
30th March 2009, 12:49
I was successful with the following approach:



QStandardItem item2 = new QStandardItem(...);
QImage glyph(QImage::fromData(pBuffer, glyph_bin_string.size(), "PNG" ));
if(!glyph.isNull())
{
QIcon description_icon(QPixmap::fromImage(glyph));
static const QSize hint(100, 100);
description_icon.actualSize(hint);
item2->setSizeHint(hint);
item2->setIcon(description_icon);
}


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

jpujolf
31st March 2009, 07:56
Have you tried with styles ?

Take a look at this (http://www.qtcentre.org/forum/f-qt-programming-2/t-qtreeview-selection-style--19181.html)

sternocera
31st March 2009, 14:08
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/stylesheet-examples.html#customizing-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

jpujolf
31st March 2009, 14:38
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 :



QTreeView::item:focus
{
background-color:rgba(150, 150, 150, 150);
color:darkblue;"
}


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

sternocera
31st March 2009, 14:55
jpujolf,

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

Regards,
Sternocera