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