PDA

View Full Version : Widget without window decoration in windows



jiveaxe
26th June 2008, 16:14
Hi,
inspired by k3b osd I have added to my application an osd widget; now it works good in linux but in windows the widget decoration (borders) is visible. Here is the code I have used:


GmckJobProgressOSD::GmckJobProgressOSD( QWidget* parent )
: QWidget( parent, Qt::Window | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint ),
m_dirty(true),
m_progress(0),
m_dragging(false),
m_screen(0),
m_position(s_outerMargin, s_outerMargin)
{
QPixmap pix(10,10);
m_osdBuffer = pix;
setFocusPolicy( Qt::NoFocus );

// dummy size
resize( 100, 20 );
}


void GmckJobProgressOSD::renderOSD()
{
// -----------------------------------------
// | download |
// | GMCK ========== 40% |
// | |
// -----------------------------------------

// calculate needed size
if( true ) {
QPixmap icon(":/icons/icon16x16.png");
int margin = 10;
int textWidth = fontMetrics().width( m_text );

// do not change the size every time the text changes, just in case we are too small
QSize newSize( qMax( qMax( 2*margin + icon.width() + margin + textWidth, 100 ), width() ),
qMax( 2*margin + icon.height(), 2*margin + fontMetrics().height()*2 ) );

m_osdBuffer = m_osdBuffer.scaled( newSize );
QPainter p( &m_osdBuffer );

p.setPen( Qt::white );

// draw the background and the frame
QRect thisRect( -1, -1, newSize.width()+1, newSize.height()+1 );
p.fillRect( thisRect, QColor(233,116,37));
p.drawRect( thisRect );

// draw the gmck icon
p.drawPixmap( margin, (newSize.height()-icon.height())/2, icon );

// draw the text
QSize textSize = fontMetrics().size( 0, m_text );
int textX = 2*margin + icon.width();
int textY = margin + fontMetrics().ascent();
p.drawText( textX, textY, m_text );

// draw the progress
textY += fontMetrics().descent() + 4;
QRect progressRect( textX, textY, newSize.width()-textX-margin, newSize.height()-textY-margin );
p.drawRect( progressRect );
progressRect.setWidth( m_progress > 0 ? m_progress*progressRect.width()/100 : 0 );
p.fillRect( progressRect, Qt::white );

// reposition the osd
reposition( newSize );
resize(newSize);

m_dirty = false;

update();
}
}


void GmckJobProgressOSD::paintEvent( QPaintEvent* )
{
QPainter *p = new QPainter(this);
p->drawPixmap(0,0,m_osdBuffer);
}


Can I obtain the same aspect in windows too? How?

Thanks

mcosta
26th June 2008, 16:57
Set the FramelessWindowHint flag



GmckJobProgressOSD::GmckJobProgressOSD( QWidget* parent )
: QWidget( parent, Qt::Window
| Qt::WindowStaysOnTopHint
| Qt::X11BypassWindowManagerHint
| Qt::FramelessWindowHint ),
....

jiveaxe
26th June 2008, 20:25
Thank you, mcosta,
now it works good.