[Qt-interest] Fwd: How can I grab a widget and make the pixmap's background transparency?

Amit Kumar Sharma qtbond007 at gmail.com
Thu Jul 23 07:59:53 CEST 2009


Forgot to fwd it to list


---------- Forwarded message ----------
From: Amit Kumar Sharma <qtbond007 at gmail.com>
Date: Thu, Jul 23, 2009 at 11:29 AM
Subject: Re: [Qt-interest] How can I grab a widget and make the
pixmap's background transparency?
To: Kermit Mei <kermit.mei at gmail.com>


I suggest you create a master pixmap and fill it with Qt::transperant.
Then you grabWidget for all the widgets of the parent widget that you
want to copy. Draw these pixmaps on the master.
While drawing the child widget pixmaps on the master you will have to
translate to the child widget coordinates.

Here is a crude algo :

QObjectList  listChild = pParentWidget->children();
QPixmap     pixMaster(pParentWidget->size());

pixMaster.fillColor(Qt::transperant); // make background transperant

QPainter   painter(&pixMaster);

for all listChild
{
  QWidget *pChild = dynamic_cast<QWidget*>(listChild.at(nCtr);
    QPixmap pixChild =QWidget::grabWidget( pChild, pChild->rect());

    // now paint the whole pixmap on the master at its position
    painter->drawPixmap(pChild->pos(),pixChild,pixChild.rect());

}



On Wed, Jul 22, 2009 at 4:20 PM, Kermit Mei<kermit.mei at gmail.com> wrote:
> On Wed, 2009-07-22 at 15:41 +0530, Amit Kumar Sharma wrote:
>> Use
>>
>>
>> pixmap.fillColor(Qt::transparent);
>>
>>
>> Cheers
>>
>>
>> AK
>
> AK, do you mean QPixmap::file(const QColor &) ?
>
> I know this method, but it can't help me complete my work.
>
> Firstly, I need a QWidget's pixmap, and there're some buttons on the
> QWidget object for example. Now, I need a pixmap that get by
> QPixmap::grabWidget(...), the pixmap can show the buttons on the widget,
> but the other area should be transparent. Because I must draw the
> picture and show the program's background at the time.
>
> Thank you, all the same.  And hepe more help from you:)
>
> Kermit
>
>




More information about the Qt-interest-old mailing list