Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, May 2008
Transparent webkit plugin using QScrollArea


Message 1 in thread

Hi Everybody, 

I have written a webkit plugin to display custom data using a QScrollArea derived widget. The widget works well using the default palette mechanism to draw a base (white) background, which is suitable for when the widget is used in normal applications. 

I would like the plugin to be able to draw the widget transparently over the HTML background - whatever color or image that might be. I tried just creating a QWidget and setAttribute( Qt::WA_NoSystemBackground, true ) which worked - the HTML background appeared. 

Then I tried creating a QScrollArea with a sub widget, and set the attribute on the scroll area, its viewport() and its widget(). The viewport area is still drawn as white. It then changes to black as soon as I resize the window. 

Strangely, the derived widget has content margins set, and that space between the viewport and the scroll area is correctly transparent. 

How can I get the QScrollArea viewport to be transparent? 

Here is the plugin routine with a plain QScrollArea: 

QObject *Test::create(
		const QString &mimeType,
		const QUrl &url,
		const QStringList &argumentNames,
		const QStringList &argumentValues ) const
{
	QScrollArea *test = new QScrollArea();
	test->setAttribute( Qt::WA_NoSystemBackground, true );

	QWidget *w = new QWidget();
	w->setGeometry( 0, 0, 50, 50 );
	test->setWidget( w );
	test->viewport()->setAttribute( Qt::WA_NoSystemBackground, true );
	test->widget()->setAttribute( Qt::WA_NoSystemBackground, true );

	return test;
}

Many thanks in advance, 

Tony Rietwyk

--
 [ signature omitted ] 

Message 2 in thread

Answering my own question...

> Hi Everybody, 
> 
> I have written a webkit plugin to display custom data using a 
> QScrollArea derived widget. The widget works well using the 
> default palette mechanism to draw a base (white) background, 
> which is suitable for when the widget is used in normal applications. 
> 
> I would like the plugin to be able to draw the widget 
> transparently over the HTML background - whatever color or 
> image that might be. I tried just creating a QWidget and 
> setAttribute( Qt::WA_NoSystemBackground, true ) which worked 
> - the HTML background appeared. 
> 
> Then I tried creating a QScrollArea with a sub widget, and 
> set the attribute on the scroll area, its viewport() and its 
> widget(). The viewport area is still drawn as white. It then 
> changes to black as soon as I resize the window. 
> 
> Strangely, the derived widget has content margins set, and 
> that space between the viewport and the scroll area is 
> correctly transparent. 
> 
> How can I get the QScrollArea viewport to be transparent? 


Here is the incantation that worked: ;O)


QObject *Test::create(
		const QString &mimeType,
		const QUrl &url,
		const QStringList &argumentNames,
		const QStringList &argumentValues ) const
{
	QScrollArea *test = new QScrollArea();
	test->setAttribute( Qt::WA_NoSystemBackground, true );
	test->setFrameShape( QFrame::NoFrame );

	QWidget *vp = new QWidget();
	vp->setAttribute( Qt::WA_NoSystemBackground, true );
	test->setViewport( vp );

	QWidget *w = new QWidget();
	w->setGeometry( 0, 0, 50, 50 );
	w->setAttribute( Qt::WA_NoSystemBackground, true );
	test->setWidget( w );

	// This MUST come after test->setWidget. 
	w->setAutoFillBackground( false );

	return test;
}

Regards, 

--
 [ signature omitted ]