Results 1 to 9 of 9

Thread: Qt setMask and resizing

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Qt setMask and resizing

    Are you sure there is no simpler way ?

    Anybody reimplemented the resize window algorithm on a QWidget ?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt setMask and resizing

    Quote Originally Posted by bunjee View Post
    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.
    J-P Nurmi

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt setMask and resizing

    Give it a try:
    Qt Code:
    1. // main.cpp
    2. #include <QtGui>
    3.  
    4. class MaskWindow : public QWidget
    5. {
    6. public:
    7. MaskWindow()
    8. {
    9. QGridLayout* grid = new QGridLayout(this);
    10. grid->addWidget(new QSizeGrip(this), 0, 0, Qt::AlignTop | Qt::AlignLeft);
    11. grid->addWidget(new QSizeGrip(this), 0, 2, Qt::AlignTop | Qt::AlignRight);
    12. grid->addWidget(new QSizeGrip(this), 2, 0, Qt::AlignBottom | Qt::AlignLeft);
    13. grid->addWidget(new QSizeGrip(this), 2, 2, Qt::AlignBottom | Qt::AlignRight);
    14. grid->addWidget(new QLabel("Content", this), 1, 1, Qt::AlignCenter);
    15. grid->setSpacing(0);
    16. grid->setMargin(0);
    17. }
    18.  
    19. protected:
    20. void resizeEvent(QResizeEvent* event)
    21. {
    22. QWidget::resizeEvent(event);
    23. setMask(rect());
    24. }
    25. };
    26.  
    27. int main(int argc, char *argv[])
    28. {
    29. QApplication a(argc, argv);
    30. MaskWindow w;
    31. w.show();
    32. return a.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. The following user says thank you to jpn for this useful post:

    bunjee (21st November 2007)

  5. #4
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: Qt setMask and resizing

    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.

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Qt setMask and resizing

    Quote Originally Posted by bunjee View Post
    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.
    J-P Nurmi

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
  •  
Qt is a trademark of The Qt Company.