本文介绍了Qt:调整无边框小部件的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题与(或直接在QtCreator表单设计器中)。



对于自定义窗口小部件方式可能是使用。我没有使用它自己,但你可以检查git的Qt源代码或。 p>

My question is basically the same as this one, but applied to the Qt C++ framework.

I am implementing a popup window by inheriting QWidget with flags Qt::QPopup | Qt::QWindow. I would like this window to be moveable and resizeable, I'm currently achieving this by using the mouse events in the following code:

void TextPopup::mousePressEvent(QMouseEvent* event)
{
    offset = event->pos();
    QWidget::mousePressEvent(event);
}

void TextPopup::mouseMoveEvent(QMouseEvent* event)
{
    if(event->buttons() & Qt::LeftButton)
        if(resizeMode) {
            QPoint p = mapToGlobal(event->pos()) - geometry().topLeft();
            resize(p.x(), p.y());
        } else
            move(mapToParent(event->pos() - offset));
    else {
        QPoint diff = geometry().bottomRight() - mapToGlobal(event->pos());
        if(diff.x() <= 6 && diff.y() <= 6) {
            if(!resizeMode) {
                setCursor(Qt::SizeFDiagCursor);
                resizeMode = true;
            }
        } else {
            if(resizeMode) {
                setCursor(Qt::SizeAllCursor);
                resizeMode = false;
            }
        }
    }
}

void TextPopup::mouseReleaseEvent(QMouseEvent* event)
{
    offset = QPoint();
    QWidget::mouseReleaseEvent(event);
}

I have a few problems with this. For one, I'm guessing there's a better way to do it. And more importantly, I would like the resize symbol at the bottom right as in this image (taken from the post mentioned above). Any suggestions for achieving this?

解决方案

You can add the resize grip by calling QDialog's or QStatusBar's function setSizeGripEnabled (or directly in QtCreator form designer).

For custom widgets the simplest way probably is to use QSizeGrip. I didn't use it myself but you can check the Qt source code on git for QStatusBar or QDialog.

这篇关于Qt:调整无边框小部件的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:40