in the widget constructor :
MyWidget
::MyWidget(QWidget *parent
){
//...
setWindowFlags( Qt::FramelessWindowHint ) ;
setAttribute( Qt::WA_TranslucentBackground );
//...
}
MyWidget::MyWidget(QWidget *parent)
: QGraphicsView(parent)
{
//...
setWindowFlags( Qt::FramelessWindowHint ) ;
setAttribute( Qt::WA_TranslucentBackground );
//...
}
To copy to clipboard, switch view to plain text mode
Then, you have to reimplement your widget's ::paintEvent method :
{
// draw widget's frame and titlebar
if( p_cache!=NULL )
{
painter.drawPixmap(0, 0, *p_cache);
}
// draw scene items
}
void MyWidget::paintEvent(QPaintEvent * e)
{
QPainter painter( viewport() );
// draw widget's frame and titlebar
if( p_cache!=NULL )
{
painter.drawPixmap(0, 0, *p_cache);
}
// draw scene items
QGraphicsView::paintEvent(e);
}
To copy to clipboard, switch view to plain text mode
And manage a cached pixmap :
{
// redraw window
invalidateCache() ;
}
void MyWidget::invalidateCache( void )
{
if( p_cache!=NULL )
{
delete p_cache;
}
p_cache
->fill
(QColor(0,
0,
0,
1)/*Qt::transparent*/);
// draw whatever you want
// ...
}
void MyWidget::resizeEvent(QResizeEvent *)
{
// redraw window
invalidateCache() ;
}
void MyWidget::invalidateCache( void )
{
if( p_cache!=NULL )
{
delete p_cache;
}
p_cache = new QPixmap(size());
p_cache->fill(QColor(0,0,0,1)/*Qt::transparent*/);
// draw whatever you want
// ...
}
To copy to clipboard, switch view to plain text mode
worked for me
(and i was wrong: apparently the window is fully transparent)
Bookmarks