-
Автор темы
- #1
Приветствую. У меня произошла трагедия, страшная...
Я делал GUI для программы на Python, я это конвертировал в .py код, начал делать виджет для отключения обрамления и его последующее перемещение.
Но было бы все так просто. В этом куске кода мы запускаем виджет:
Но, как отрисовать виджет и главное окно, чтобы я смог перемещать окно без обрамления и привязывать функции к кнопкам ? Скажите пж если кто знает.
Вот весь код:
@ catahustle @ Irval Помогите 5-ти летнему пастеру.
Я делал GUI для программы на Python, я это конвертировал в .py код, начал делать виджет для отключения обрамления и его последующее перемещение.
Но было бы все так просто. В этом куске кода мы запускаем виджет:
Python:
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
Вот весь код:
Код:
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QDesktopWidget
from PyQt5.QtCore import QPoint
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(821, 481)
self.fon = QtWidgets.QLabel(Form)
self.fon.setGeometry(QtCore.QRect(0, 0, 821, 481))
self.fon.setStyleSheet("background-color: rgb(25,25,25);")
self.fon.setText("")
self.fon.setObjectName("fon")
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(0, 0, 821, 31))
self.label.setStyleSheet("background-color: rgb(90,90,90);")
self.label.setText("")
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(Form)
self.label_2.setGeometry(QtCore.QRect(45, 1, 55, 30))
self.label_2.setStyleSheet("font: 75 18pt \"Tahoma\";")
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(Form)
self.label_3.setGeometry(QtCore.QRect(90, 45, 99, 25))
self.label_3.setStyleSheet("font: 16pt \"Tahoma\";")
self.label_3.setObjectName("label_3")
self.pushButton_1 = QtWidgets.QPushButton(Form)
self.pushButton_1.setGeometry(QtCore.QRect(20, 80, 115, 35))
self.pushButton_1.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_1.setObjectName("pushButton_1")
self.pushButton_2 = QtWidgets.QPushButton(Form)
self.pushButton_2.setGeometry(QtCore.QRect(146, 80, 115, 35))
self.pushButton_2.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_2.setObjectName("pushButton_2")
self.label_6 = QtWidgets.QLabel(Form)
self.label_6.setGeometry(QtCore.QRect(103, 136, 72, 25))
self.label_6.setStyleSheet("font: 16pt \"Tahoma\";")
self.label_6.setObjectName("label_6")
self.pushButton_3 = QtWidgets.QPushButton(Form)
self.pushButton_3.setGeometry(QtCore.QRect(20, 170, 115, 35))
self.pushButton_3.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_4 = QtWidgets.QPushButton(Form)
self.pushButton_4.setGeometry(QtCore.QRect(146, 170, 115, 35))
self.pushButton_4.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_4.setObjectName("pushButton_4")
self.label_8 = QtWidgets.QLabel(Form)
self.label_8.setGeometry(QtCore.QRect(100, 224, 91, 25))
self.label_8.setStyleSheet("font: 16pt \"Tahoma\";")
self.label_8.setObjectName("label_8")
self.pushButton_5 = QtWidgets.QPushButton(Form)
self.pushButton_5.setGeometry(QtCore.QRect(20, 260, 241, 35))
self.pushButton_5.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_5.setObjectName("pushButton_5")
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(20, 345, 241, 31))
self.lineEdit.setStyleSheet("color: rgb(255,255,255);\n"
"background-color: rgb(40,40,40);\n"
"font: 18pt \"Tahoma\";\n"
"\n"
"border-width: 1px;\n"
"border-style: solid;\n"
"border-color: red;\n"
"\n"
"padding-left: 5 px;\n"
"padding-right: 5 px;")
self.lineEdit.setText("")
self.lineEdit.setMaxLength(10)
self.lineEdit.setObjectName("lineEdit")
self.pushButton_6 = QtWidgets.QPushButton(Form)
self.pushButton_6.setGeometry(QtCore.QRect(20, 385, 115, 35))
self.pushButton_6.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_6.setObjectName("pushButton_6")
self.pushButton_7 = QtWidgets.QPushButton(Form)
self.pushButton_7.setGeometry(QtCore.QRect(146, 385, 115, 35))
self.pushButton_7.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_7.setObjectName("pushButton_7")
self.pushButton_8 = QtWidgets.QPushButton(Form)
self.pushButton_8.setGeometry(QtCore.QRect(20, 430, 241, 35))
self.pushButton_8.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_8.setObjectName("pushButton_8")
self.pushButton_9 = QtWidgets.QPushButton(Form)
self.pushButton_9.setGeometry(QtCore.QRect(290, 80, 115, 35))
self.pushButton_9.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_9.setObjectName("pushButton_9")
self.pushButton_10 = QtWidgets.QPushButton(Form)
self.pushButton_10.setGeometry(QtCore.QRect(415, 80, 115, 35))
self.pushButton_10.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_10.setObjectName("pushButton_10")
self.pushButton_11 = QtWidgets.QPushButton(Form)
self.pushButton_11.setGeometry(QtCore.QRect(290, 170, 115, 35))
self.pushButton_11.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_11.setObjectName("pushButton_11")
self.pushButton_12 = QtWidgets.QPushButton(Form)
self.pushButton_12.setGeometry(QtCore.QRect(415, 170, 115, 35))
self.pushButton_12.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_12.setObjectName("pushButton_12")
self.pushButton_13 = QtWidgets.QPushButton(Form)
self.pushButton_13.setGeometry(QtCore.QRect(560, 80, 241, 35))
self.pushButton_13.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_13.setObjectName("pushButton_13")
self.pushButton_14 = QtWidgets.QPushButton(Form)
self.pushButton_14.setGeometry(QtCore.QRect(560, 125, 241, 35))
self.pushButton_14.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_14.setObjectName("pushButton_14")
self.pushButton_15 = QtWidgets.QPushButton(Form)
self.pushButton_15.setGeometry(QtCore.QRect(560, 170, 241, 35))
self.pushButton_15.setStyleSheet("QPushButton{\n"
" background-color: rgb(55,55,55);\n"
" color: white;\n"
" font-size: 15px;\n"
" font-weight: bold;\n"
" border: solid;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" background-color: rgb(70,70,70);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" background-color: rgb(80,80,80);\n"
"}")
self.pushButton_15.setObjectName("pushButton_15")
self.pushButton_16 = QtWidgets.QPushButton(Form)
self.pushButton_16.setGeometry(QtCore.QRect(790, 0, 31, 31))
self.pushButton_16.setStyleSheet("QPushButton{\n"
" color: rgb(253,25,1);\n"
" background-color: rgb(90,90,90);\n"
" font-size: 18px;\n"
" font-weight: bold;\n"
" border: none;\n"
" text-align: center;\n"
"}\n"
"\n"
"QPushButton:hover {\n"
" color: rgb(253,80,0);\n"
"}\n"
"\n"
"QPushButton:pressed {\n"
" color: rgb(253,100,0);\n"
"}\n"
"")
self.pushButton_16.setObjectName("pushButton_16")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Hide"))
self.label_2.setText(_translate("Form", "<html><head/><body><p><span style=\" font-weight:600; color:#55aaff;\">test</span></p></body></html>"))
self.label_3.setText(_translate("Form", "<html><head/><body><p><span style=\" font-weight:600; color:#ffff00;\">test</span></p></body></html>"))
self.pushButton_1.setText(_translate("Form", "test"))
self.pushButton_2.setText(_translate("Form", "test"))
self.label_6.setText(_translate("Form", "<html><head/><body><p><span style=\" font-weight:600; color:#ffff00;\">test</span></p></body></html>"))
self.pushButton_3.setText(_translate("Form", "test"))
self.pushButton_4.setText(_translate("Form", "test"))
self.label_8.setText(_translate("Form", "<html><head/><body><p><span style=\" font-weight:600; color:#ffff00;\">test</span></p></body></html>"))
self.pushButton_5.setText(_translate("Form", "test"))
self.lineEdit.setPlaceholderText(_translate("Form", "01.01.2021"))
self.pushButton_6.setText(_translate("Form", "test"))
self.pushButton_7.setText(_translate("Form", "test"))
self.pushButton_8.setText(_translate("Form", "test"))
self.pushButton_9.setText(_translate("Form", "Запустить"))
self.pushButton_10.setText(_translate("Form", "Остановить"))
self.pushButton_11.setText(_translate("Form", "test"))
self.pushButton_12.setText(_translate("Form", "test"))
self.pushButton_13.setText(_translate("Form", "test"))
self.pushButton_14.setText(_translate("Form", "test"))
self.pushButton_15.setText(_translate("Form", "test"))
self.pushButton_16.setText(_translate("Form", "✕"))
class Widget(QtWidgets.QWidget, Ui_Form):
def __init__(self, parent=None):
super(Widget, self).__init__(parent)
self.setupUi(self)
self.center()
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def mousePressEvent(self, event):
self.oldPos = event.globalPos()
def mouseMoveEvent(self, event):
delta = QPoint (event.globalPos() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
#if __name__ == "__main__":
# import sys
# app = QtWidgets.QApplication(sys.argv)
# Form = QtWidgets.QWidget()
# ui = Ui_Form()
# ui.setupUi(Form)
# Form.show()
# sys.exit(app.exec_())
Последнее редактирование: