4

How can I implement QSizeGrip with a Qt frameless window?

What would the code be like?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Eagle Eye
  • 91
  • 1
  • 6

1 Answers1

12

You just have to add a QSizeGrip in a corner of your window inside a layout to make it stay in that corner.

QDialog *dialog = new QDialog(0, Qt::FramelessWindowHint);
QVBoxLayout *layout = new QVBoxLayout(dialog);

// To remove any space between the borders and the QSizeGrip...      
layout->setContentsMargins(QMargins());         
// and between the other widget and the QSizeGrip
layout->setSpacing(0);
layout->addWidget(new QTextEdit(dialog));

// The QSizeGrip position (here Bottom Right Corner) determines its
// orientation too
layout->addWidget(new QSizeGrip(dialog), 0, Qt::AlignBottom | Qt::AlignRight);

dialog->show();
alexisdm
  • 29,448
  • 6
  • 64
  • 99
  • 3
    And what if it is a child of a widget? When I add it to an QHBoxLayout, it "pushes" all of my widgets over to the left so I would like to make it the child of a widget that it can sit on "top" of – Spencer May 15 '18 at 17:23
  • @Spencer You may not like it, but use a `QGridLayout`. That way, you can avoid it resizing everything else. It's not that much extra effort. You can also just add another widget that will hold everything below, set it to have a stretch to fill, and have the size grip have a stretch to 0. – Alex Huszagh May 05 '22 at 22:55