Results 1 to 3 of 3

Thread: Widget without window decoration in windows

  1. #1
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Widget without window decoration in windows

    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:
    Qt Code:
    1. GmckJobProgressOSD::GmckJobProgressOSD( QWidget* parent )
    2. : QWidget( parent, Qt::Window | Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint ),
    3. m_dirty(true),
    4. m_progress(0),
    5. m_dragging(false),
    6. m_screen(0),
    7. m_position(s_outerMargin, s_outerMargin)
    8. {
    9. QPixmap pix(10,10);
    10. m_osdBuffer = pix;
    11. setFocusPolicy( Qt::NoFocus );
    12.  
    13. // dummy size
    14. resize( 100, 20 );
    15. }
    16.  
    17.  
    18. void GmckJobProgressOSD::renderOSD()
    19. {
    20. // -----------------------------------------
    21. // | download |
    22. // | GMCK ========== 40% |
    23. // | |
    24. // -----------------------------------------
    25.  
    26. // calculate needed size
    27. if( true ) {
    28. QPixmap icon(":/icons/icon16x16.png");
    29. int margin = 10;
    30. int textWidth = fontMetrics().width( m_text );
    31.  
    32. // do not change the size every time the text changes, just in case we are too small
    33. QSize newSize( qMax( qMax( 2*margin + icon.width() + margin + textWidth, 100 ), width() ),
    34. qMax( 2*margin + icon.height(), 2*margin + fontMetrics().height()*2 ) );
    35.  
    36. m_osdBuffer = m_osdBuffer.scaled( newSize );
    37. QPainter p( &m_osdBuffer );
    38.  
    39. p.setPen( Qt::white );
    40.  
    41. // draw the background and the frame
    42. QRect thisRect( -1, -1, newSize.width()+1, newSize.height()+1 );
    43. p.fillRect( thisRect, QColor(233,116,37));
    44. p.drawRect( thisRect );
    45.  
    46. // draw the gmck icon
    47. p.drawPixmap( margin, (newSize.height()-icon.height())/2, icon );
    48.  
    49. // draw the text
    50. QSize textSize = fontMetrics().size( 0, m_text );
    51. int textX = 2*margin + icon.width();
    52. int textY = margin + fontMetrics().ascent();
    53. p.drawText( textX, textY, m_text );
    54.  
    55. // draw the progress
    56. textY += fontMetrics().descent() + 4;
    57. QRect progressRect( textX, textY, newSize.width()-textX-margin, newSize.height()-textY-margin );
    58. p.drawRect( progressRect );
    59. progressRect.setWidth( m_progress > 0 ? m_progress*progressRect.width()/100 : 0 );
    60. p.fillRect( progressRect, Qt::white );
    61.  
    62. // reposition the osd
    63. reposition( newSize );
    64. resize(newSize);
    65.  
    66. m_dirty = false;
    67.  
    68. update();
    69. }
    70. }
    71.  
    72.  
    73. void GmckJobProgressOSD::paintEvent( QPaintEvent* )
    74. {
    75. QPainter *p = new QPainter(this);
    76. p->drawPixmap(0,0,m_osdBuffer);
    77. }
    To copy to clipboard, switch view to plain text mode 

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

    Thanks
    Giuseppe CalÃ

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Widget without window decoration in windows

    Set the FramelessWindowHint flag

    Qt Code:
    1. GmckJobProgressOSD::GmckJobProgressOSD( QWidget* parent )
    2. : QWidget( parent, Qt::Window
    3. | Qt::WindowStaysOnTopHint
    4. | Qt::X11BypassWindowManagerHint
    5. | Qt::FramelessWindowHint ),
    6. ....
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Aug 2007
    Posts
    244
    Thanks
    42
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget without window decoration in windows

    Thank you, mcosta,
    now it works good.
    Giuseppe CalÃ

Similar Threads

  1. Replies: 4
    Last Post: 23rd December 2008, 20:41
  2. Replies: 1
    Last Post: 11th September 2007, 13:34
  3. qtopia window decoration cannot show caption
    By qtopiahooo in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 13th March 2007, 08:09
  4. window decoration cannot show caption
    By qtopiahooo in forum Qt Programming
    Replies: 1
    Last Post: 31st January 2007, 08:17
  5. Replies: 5
    Last Post: 4th August 2006, 23:44

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.