PDA

View Full Version : transparent pixmap



marcus
23rd May 2010, 20:16
Hi!

Im trying to create an transparant pixmap to use in a listview. The best result I get is to use createHeuristicMask which isn't good enough.

I have been trying to fill the pixmap with an transparent image first, but not succeceded.

Im using Qt 3.3 and here is the code that im trying to experiment with at the moment.

#include <qapplication.h>
#include <qlistview.h>
#include <qpainter.h>
#include <qpixmap.h>
#include <qbitmap.h>

int main ( int argc, char **argv )
{

QApplication app ( argc,argv );

QListView *listview=new QListView();
listview->addColumn ( "test" );

QListViewItem *item1=new QListViewItem ( listview );
item1->setText ( 0,"testing text" );

QListViewItem *item2=new QListViewItem ( listview );
QPixmap pixmap ( 150,50 );
pixmap.fill ( Qt::white );
QPainter painter ( &pixmap );
painter.drawText ( 15,15,"testing pixmap" );
painter.end();
pixmap.setMask(pixmap.createHeuristicMask());
item2->setPixmap ( 0,pixmap );

app.setMainWidget ( listview );
listview->show();

return app.exec();
}

Lykurg
23rd May 2010, 22:20
What's about
pixmap.fill ( Qt::color0 );? Does that work?

marcus
24th June 2010, 20:16
nope, that didn't work :(

aamer4yu
25th June 2010, 05:47
What class is QListViewItem ? Its not a standard Qt class.
also seems you want a common background for the list view and hence you want the transparent pixmap for the item, am i right ??

marcus
25th June 2010, 10:03
QListViewItem is defined in listview.h in Qt 3.3 in Linux. (QListViewItem is not an QWidget, just a helper for QListView)

Yes, I want to create a pixmap with transparant background, so the background of the listview is still visible (or actually the listviewitem, which can be blue (selected) or white (not selected))

I have been able to load a png-file with transparant background, and then load it in to the listview, this works exacly the way I want't it to.

createHeuristicMask() works, but the output is very ugly. and letters wich surround white areas, such as "0" or "6" doesn't get transparent.

aamer4yu
25th June 2010, 14:45
Qt 3.3 :O

wud suggest to upgrade to 4.6.3 unless you have some boundations.
4.7 is also coming this year...

marcus
25th June 2010, 15:21
ok, i will try qt463. can you recommomend any beginner guide for people used to 3.3?

marcus
25th June 2010, 15:22
qt 4.6.2 seems to be installed on my ubuntu.. good enough? :)