K
K
kokapuk2022-02-16 21:56:51
Qt
kokapuk, 2022-02-16 21:56:51

How to make a frameless Qt draggable window?

I know about ways by type

void mousePressEvent(QMouseEvent *evt)
        {
            oldPos = evt->globalPos();
        }

        void mouseMoveEvent(QMouseEvent *evt)
        {
            const QPoint delta = evt->globalPos() - oldPos;
            if (locked)
                // if locked, ignore delta on y axis, stay at the top
                move(x()+delta.x(), y()); 
            else
                move(x()+delta.x(), y()+delta.y());
            oldPos = evt->globalPos();
        }

But I wanted to know if it's possible to do it more correctly, like in WPF, just call DragMove() on the click event. Or like in electrone, just designating DragRegion? Just, for example, the same telegram desktop, as far as I know, it is on Qt, and at the same time it has a frameless window with the "correct" drag and drop.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jacob E, 2022-02-18
@kokapuk

Relatively recently, this thing appeared: https://www.qt.io/blog/custom-window-decorations
Before 5.15 there was no easy way, so if you need an older version, you can not reinvent the wheel, but take a ready-made implementation: https://github.com/search?q=Qt+frameless

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question