Qt中layout()->setSizeConstraint(QLayout::SetFixedSize);崩溃的问题

在《C++ GUI Qt 4编程》中,如果误操作,在最后一步设置窗口布局为“栅格布局”的时候,忘记设置

那么就会出现

layout()->setSizeConstraint(QLayout::SetFixedSize);崩溃的问题

处理方法:

layout()->setSizeConstraint(QLayout::SetFixedSize);崩溃的问题

处理方法:


文章图片来源:https://blog.csdn.net/lslsyqyq/article/details/8254702

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如何将以下代码转成pyside6的 #include <QtGui> class GripLabel: public QLabel { Q_OBJECT public: GripLabel(QString const& title, QWidget* parent = 0) : QLabel(title, parent), resizing(false), gripSize(10, 10) { // Prevent the widget from disappearing altogether // Bare minimum would be gripSize setMinimumSize(100, 30); } QSize sizeHint() const { return minimumSize(); } protected: bool mouseInGrip(QPoint mousePos) { // "handle" is in the lower right hand corner return ((mousePos.x() > (width() - gripSize.width())) && (mousePos.y() > (height() - gripSize.height()))); } void mousePressEvent(QMouseEvent *e) { // Check if we hit the grip handle if (mouseInGrip(e->pos())) { oldPos = e->pos(); resizing = true; } else { resizing = false; } } void mouseMoveEvent(QMouseEvent *e) { if (resizing) { // adapt the widget size based on mouse movement QPoint delta = e->pos() - oldPos; oldPos = e->pos(); setMinimumSize(width()+delta.x(), height()+delta.y()); updateGeometry(); } } void paintEvent(QPaintEvent *e) { QLabel::paintEvent(e); QPainter p(this); p.setPen(Qt::red); p.drawRect(width()-gripSize.width(), height()-gripSize.height(), gripSize.width(), gripSize.height()); } private: bool resizing; QSize gripSize; QPoint oldPos; }; sample 主要: #include "griplabel.h" int main(int argc, char **argv) { QApplication app(argc, argv); QWidget *w = new QWidget; QPushButton *b = new QPushButton("button"); GripLabel *l = new GripLabel("Hello"); QHBoxLayout *y = new QHBoxLayout; y->addWidget(b); y->addWidget(l); y->setSizeConstraint(QLayout::SetFixedSize); w->setLayout(y); w->show(); return app.exec(); }
05-31

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值