'PyQt: QDrag a shortcut to the Windows Taskbar
My app has some auto-generated windows shortcuts (.lnk files) that I want to give the user the ability to drag to their taskbar.
I'm using PyQT5, Python 3.8, and Windows 10.
Here is a simplified example of what I'm trying to do:
from PyQt5 import QtWidgets, QtCore, QtGui
class ExampleApp(QtWidgets.QWidget):
def __init__(self, parent=None) -> None:
super().__init__(parent)
self.setWindowTitle("Drag Shortcut Example")
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(QtWidgets.QLabel("Click and drag shortcut."))
self.resize(400, 300)
def mousePressEvent(self, a0: QtGui.QMouseEvent) -> None:
# Microsoft Edge shortcut for example
shortcut = (
"C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\Microsoft Edge.lnk"
)
drag = QtGui.QDrag(self)
mime = QtCore.QMimeData()
mime.setUrls([QtCore.QUrl.fromLocalFile(shortcut)])
drag.setMimeData(mime)
drag.exec(QtCore.Qt.CopyAction)
if __name__ == "__main__":
app = QtWidgets.QApplication([])
window = ExampleApp()
window.show()
app.exec_()
This works perfectly fine for dragging the shortcut to the desktop, but for some reason dragging to the taskbar doesn't work.
If I drag this shortcut to the desktop, and THEN drag it from the desktop to the taskbar it works fine.
Is QT doing something different from windows for the drag event? Is there something I'm doing wrong that makes it incompatible with the taskbar?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|