PDA

View Full Version : Qt setMask and resizing



bunjee
21st November 2007, 12:32
Hey there,

I'm specifiying a mask using setMask on my main Widget.
Graphicaly It's working fine.

The only problem is the fact that I loose the window control for resizing.

Is it possible to enable it back?

Thanks.

wysota
21st November 2007, 12:58
Could you explain? What do you mean you lose control for resizing? You mask out the corner?

bunjee
21st November 2007, 13:34
Yes,

I've masked the borders and the corners.

I guess the behaviour I'd like to optain is : even if the borders and corners are hidden, still process the user's event like stretching and resizing.

jpn
21st November 2007, 13:39
I've masked the borders and the corners.
Resizing by dragging from window decoration is provided by the underlying window system, not by Qt. So unfortunately, if you mask the decoration out, you're on your own. You can try to make use of QSizeGrip.

bunjee
21st November 2007, 14:14
Are you sure there is no simpler way ?

Anybody reimplemented the resize window algorithm on a QWidget ?

jpn
21st November 2007, 14:17
Are you sure there is no simpler way ?
What's more simple than placing a QSizeGrip into each corner (possibly with help of QGridLayout) and voilá? Optionally you can subclass QSizeGrip and reimplement its paintEvent() handler to draw nothing. I mean, QSizeGrip provides resizing functionality into each direction out of the box.

jpn
21st November 2007, 14:37
Give it a try:


// main.cpp
#include <QtGui>

class MaskWindow : public QWidget
{
public:
MaskWindow()
{
QGridLayout* grid = new QGridLayout(this);
grid->addWidget(new QSizeGrip(this), 0, 0, Qt::AlignTop | Qt::AlignLeft);
grid->addWidget(new QSizeGrip(this), 0, 2, Qt::AlignTop | Qt::AlignRight);
grid->addWidget(new QSizeGrip(this), 2, 0, Qt::AlignBottom | Qt::AlignLeft);
grid->addWidget(new QSizeGrip(this), 2, 2, Qt::AlignBottom | Qt::AlignRight);
grid->addWidget(new QLabel("Content", this), 1, 1, Qt::AlignCenter);
grid->setSpacing(0);
grid->setMargin(0);
}

protected:
void resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
setMask(rect());
}
};

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MaskWindow w;
w.show();
return a.exec();
}

bunjee
21st November 2007, 14:52
That's exactly what I just coded :).

But,
It's only working for the corners of the widget, not for the sides.

So there is more work to do to completely emulate the window's behaviour.

jpn
21st November 2007, 15:01
But,
It's only working for the corners of the widget, not for the sides.

So there is more work to do to completely emulate the window's behaviour.
That's right. You might want to take a peek into QSizeGrip sources for implementation tips. ;)