#๐Ÿ”’ PySide6 Frameless Window Snap Problem...

22 messages ยท Page 1 of 1 (latest)

oblique thicket
#

I launched a Frameless Window using PySide6. I'm trying to use the Windows 10 OS Snap feature (snapping to the top, left, or right of the monitor), but it's not working. How can I fix this?

zealous jewelBOT
#

@oblique thicket

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

gray timber
#

u have a very huge cursor

oblique thicket
oblique thicket
#

image from internet

gray timber
#

uh

full moat
oblique thicket
#
# 1. Window Flags and Attributes
self.setWindowFlags(
    QtCore.Qt.WindowType.FramelessWindowHint |
    QtCore.Qt.WindowType.Window
)
self.setAttribute(QtCore.Qt.WidgetAttribute.WA_TranslucentBackground, False)

# 2. Windows Native Style Restoration (for Snap/Resize)
if _IS_WIN:
    hwnd = int(self.winId())
    style = win32gui.GetWindowLong(hwnd, win32con.GWL_STYLE)
    win32gui.SetWindowLong(hwnd, win32con.GWL_STYLE, 
                           style | win32con.WS_CAPTION | 
                           win32con.WS_THICKFRAME | 
                           win32con.WS_MAXIMIZEBOX | 
                           win32con.WS_MINIMIZEBOX)
    win32gui.SetWindowPos(
        hwnd, None, 0, 0, 0, 0,
        win32con.SWP_NOMOVE | win32con.SWP_NOSIZE |
        win32con.SWP_NOZORDER | win32con.SWP_FRAMECHANGED
    )

# 3. Docking System Configuration
self.setDockOptions(
    QtWidgets.QMainWindow.DockOption.AllowNestedDocks |
    QtWidgets.QMainWindow.DockOption.AllowTabbedDocks |
    QtWidgets.QMainWindow.DockOption.AnimatedDocks
)
self.setTabPosition(QtCore.Qt.DockWidgetArea.AllDockWidgetAreas, 
                    QtWidgets.QTabWidget.TabPosition.North)

# 4. Native Event Handling (Hit Testing for Caption/Borders)
def nativeEvent(self, event_type, message):
    if not _IS_WIN:
        return super().nativeEvent(event_type, message)

    msg = _wt.MSG.from_address(int(message))
    if msg.message == win32con.WM_NCHITTEST:
        # Handling resize borders (HTTOP, HTBOTTOM, etc.)
        # Handling Titlebar (HTCAPTION) vs Client area (HTCLIENT)
        if in_caption and not rw_hit and not action_hit:
            return True, win32con.HTCAPTION
        return True, win32con.HTCLIENT
    return False, 0
zealous jewelBOT
#

Hey @oblique thicket!

Please edit your message to use a code block

Add a py after the three backticks.

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
full moat
zealous jewelBOT
#
Pasting large amounts of code

So that everyone can easily read your code, you can paste it in this website:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

oblique thicket
#

ok wait..

oblique thicket
full moat
#

Does any other app on your pc do the window snap when you drag it to the edges/border?

oblique thicket
zealous jewelBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.