dfct/TrueFramelessWindow

Correct way to construct window?

JSandusky opened this issue · 5 comments

What's the correct way to construct the window so that the toolbar checking functions (or is there a sample, known program using, etc somewhere)? Also had to tweak the margins in the QWinWidget in order for the resizing to function.

I'm using the following (and then adding the main frame contents to the Vertical layout later). Only real modifications I've made to source are switching the toolbar to a QWidget and exposing the Widget class' layout.

Widget::Widget(QWidget *parent)
    : QWidget(parent)
{
    QVBoxLayout* layout = new QVBoxLayout(this);
    layout->setContentsMargins(0, 0, 0, 0);

    toolBar = new QWidget();
    QHBoxLayout* toolBarLayout = new QHBoxLayout(toolBar);

    toolBarLayout->addWidget(new QLabel("SprueKit"));
    toolBarLayout->addStretch();

    layout->addWidget(toolBar);

    maximizeButton = new QPushButton(QIcon(":/Images/window/Maximize.png"), QString());
    maximizeButton->setCheckable(true);
    maximizeButton->setToolTip("Maximize");
    minimizeButton = new QPushButton(QIcon(":/Images/window/Minimize.png"), QString());
    minimizeButton->setToolTip("Minimize");
    closeButton = new QPushButton(QIcon(":/Images/window/Close.png"), QString());
    closeButton->setToolTip("Close");

    toolBarLayout->addWidget(minimizeButton);
    toolBarLayout->addWidget(maximizeButton);
    toolBarLayout->addWidget(closeButton);
}

Worked around it by handling widget layout myself in response to size events for the "tool bar."

I don't see how the toolbar response is even possible since there's the Hwnd check at the top of the message handling and it relies on WM_NCHITTEST which could never fire for a toolbar control as described in the readme or comments. The readme is in direct contradiction with the rules of Windows.

The toolbar will never hit the points needed for the checks.

dfct commented

@JSandusky, hey, sorry I left you hanging here. Resizing operations are handled by the native Windows window, which then setGeometry's the QWidget to keep pace.

Some unique things about the toolbar, the code checks to see if the mouse is over the toolbar itself, or over a child widget of the toolbar.

if (x >= BORDERWIDTH && x <= WindowRect.right - WindowRect.left - BORDERWIDTH && y >= BORDERWIDTH && y <= TOOLBARHEIGHT)

Theory being, traditionally, you should be able to click the toolbar and drag the whole around. But you also want things like the Close button, tabs, menus, etc. to function and those are child widgets of the toolbar. So if the mouse is over the toolbar widget itself, then you click & drag, but if it is over a child of the toolbar, then the hittest returns without handling it.

No worries, I managed to work around the issues I was having and all that stuff worked out fine.

Ended up having issues with drag events in that all drag/drop in the window's children were suppressed, which is really just a matter of going through the windows events and seeing what is being eaten that should get passed through ... I didn't have time to do that in order to get a demo out so I had to place it on an "until I get around to shipping" list since it's just dredge work.

This is still the most complete border-less window setup I've found for Qt so-far. Thanks.

dfct commented

Found this bug today, my apologies @JSandusky ! Fixed now

dfct commented

As of 36c6451 the drag issue is fixed and there is sample code for the toolbar + min/max/close buttons on Windows.