Answer the question
In order to leave comments, you need to log in
Why is widget positioning not working in pyQt?
There is this code:
import sys
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from PySide6.QtSvgWidgets import *
from PySide6.QtSvg import *
from PySide6 import QtCore
class MainWindow(QMainWindow):
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.moveFlag = True
self.movePosition = event.globalPos() - self.pos()
event.accept()
def mouseMoveEvent(self, event):
if Qt.LeftButton and self.moveFlag:
if self.movePosition.y() <= 50:
self.move(event.globalPos() - self.movePosition)
event.accept()
def mouseReleaseEvent(self, event):
self.moveFlag = False
def __init__(self):
super().__init__()
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
self.resize(720,500)
self.bg = QFrame()
self.bg.setStyleSheet("background-color: #e2e6e9; border: none;")
self.grid = QGridLayout(self.bg)
self.setCentralWidget(self.bg)
self.grid.setSpacing(0)
self.setLayout(self.grid)
self.svg_widget = QSvgWidget("main.svg")
self.get_size = QSvgRenderer("main.svg")
self.svg_widget.setFixedSize(self.get_size.defaultSize())
self.grid.addWidget(self.svg_widget, 0,0)
self.show()
def createApp():
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec())
createApp()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question