2
我找到了一个在无框窗口上设置边框的例子,但它不可拖动。我怎样才能使无框窗口可拖动?特别是如果我能看到一个例子,它会很棒。这是我的示例代码(通常代码更长,这就是为什么有许多库只是不介意它们);PyQt5可拖动无框窗口
from PyQt5.QtWidgets import (QMessageBox,QApplication, QWidget, QToolTip, QPushButton,
QDesktopWidget, QMainWindow, QAction, qApp, QToolBar, QVBoxLayout,
QComboBox,QLabel,QLineEdit,QGridLayout,QMenuBar,QMenu,QStatusBar,
QTextEdit,QDialog,QFrame,QProgressBar
)
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtGui import QIcon,QFont,QPixmap,QPalette
from PyQt5.QtCore import QCoreApplication, Qt,QBasicTimer
import sys
class cssden(QMainWindow):
def __init__(self):
super().__init__()
self.mwidget = QMainWindow(self)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
#size
self.setFixedSize(320, 450)
self.center
#label
self.lbl = QLabel(self)
self.lbl.setText("test")
self.lbl.setStyleSheet("background-color: rgb(0,0,0);"
"border: 1px solid red;"
"color: rgb(255,255,255);"
"font: bold italic 20pt 'Times New Roman';")
self.lbl.setGeometry(5,5,60,40)
self.show()
#center
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
app = QApplication(sys.argv)
app.setStyleSheet("QMainWindow{background-color: darkgray;border: 1px solid black}")
ex = cssden()
sys.exit(app.exec_())
的伟大工程。请问有没有鼠标事件的例子,如悬停鼠标等?只有关于C++的例子,我很难将它们转换成Python。 – GLHF
是的,我知道有很多Python例子。我认为最好的方法是了解如何将Qt C++代码转换为Python。它不像开始时那样复杂。 –
这是一个相关的[代码示例](https://gist.github.com/zed/77e705caa840bab117057952f9ca6191) – jfs