PDA

View Full Version : Qt::FramelessWindowHint resizing a widget



Plissken
2nd July 2012, 06:06
CustomWidget::CustomWidget( QWidget *parent )
: QWidget( parent )
{
setWindowFlags( Qt::FramelessWindowHint );
resize( 10, 50 );
}

void CustomWidget::paintEvent( QPaintEvent *event )
{
QPainter painter( this );
painter.setRenderHint( QPainter::Antialiasing, true );
painter.setPen( Qt::black );
painter.setBrush( QBrush( QPixmap( "images/blueblend.jpg" ) ) );
painter.drawRoundedRect(0, 0, size().width(), size().height(), 5, 25, Qt::AbsoluteSize );

}

I was just messing around with trying to learn how to make a custom widget. With the code above, I get the following widget:
http://img37.imageshack.us/img37/3286/framedj.jpg

But with the frameless window hint I get:
http://img204.imageshack.us/img204/6900/frameless.jpg


What's the reason of it getting resized? Is there a way I can resize it back?

ChrisW67
2nd July 2012, 06:24
The attachments are not working for me :(

Plissken
2nd July 2012, 06:50
Fixed the links.

ChrisW67
2nd July 2012, 08:45
To be clear, the frameless version is the correct size, i.e. 10 pixels wide, 50 high. The framed version looks like a minimum width is being forced to accommodate the window controls. On my Linux machine a similar thing happens and the control gets sized to 18x50.

Unless you intend that the 10x50 control appears in isolation on the desktop rather than part of a larger layout I cannot see the problem. What exactly is the problem you are trying to solve?

Plissken
2nd July 2012, 21:42
Ah, thanks Chris. I didn't think about minimum width being enforced for controls. The first time I ran it with the border so I thought that was 10x50.