pyqt5

Readjust the Custom QGraphicsWIdget's size on inserting widget

主宰稳场 提交于 2021-01-29 11:11:53
问题 I have created a custom QGraphicsWidget with the ability to resize the widget in the scene. I can also add predefined widgets such as buttons, labels, etc. to my custom widget. I now have two problems. The first being that the widget doesn't change the size (to re-adjust) upon inserting a new label or LineEdit widget as a result newly inserted widget stays out of the custom widget border. The second problem is encountered when I try to change the setContentMargins of the QGraphicsLayout to

PyQt5: All Items of GraphicsScene have coordinates 0.0

放肆的年华 提交于 2021-01-29 10:00:10
问题 I used the following source and modified it a bit, to get the following mini example: import sys from PyQt5 import QtCore, QtWidgets class GraphicsScene(QtWidgets.QGraphicsScene): def __init__(self): super(GraphicsScene, self).__init__() self.setSceneRect(0, 0, 600, 400) def mousePressEvent(self, event): if event.buttons() == QtCore.Qt.LeftButton: x = event.scenePos().x() y = event.scenePos().y() self.addRect(x, y, 100, 100) elif event.buttons() == QtCore.Qt.RightButton: for elem in self

PyQT different image autoscaling modes [duplicate]

橙三吉。 提交于 2021-01-29 09:07:28
问题 This question already has answers here : Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio (6 answers) Closed 2 years ago . Let's say we have a QLabel with QPixmap label = QLabel Pixmap = QPixmap('filepath') label.setPixmap(Pixmap) I already mentioned that by using label.setScaledContents(True) We can force image to be autoscaled to label size (And widget's one if label autoscaled to it) Without using it, image gona be displayed in it's full size, not depending on

popup closeEvent code with code from QtDesigner [duplicate]

一世执手 提交于 2021-01-29 09:02:22
问题 This question already has answers here : QtDesigner changes will be lost after redesign User Interface (2 answers) Closed 11 months ago . I'm trying to create a pop up message box when the "close" button is pressed. my code looks like as follow: from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtWidgets import QMessageBox class Ui_Form(object): def __init__(self): super().__init__() self.stop_request_1 = False self.stop_request_2 = False def setupUi(self, Form): Form.setObjectName("Form"

Vlc won't work with framelesswindow and transparent/translucent background in PyQt5

人走茶凉 提交于 2021-01-29 09:02:05
问题 i am making a window which plays video with vlc. Here is my code from PyQt5 import QtWidgets,QtCore,QtGui import vlc class Player(QtWidgets.QMainWindow): def __init__(self): super().__init__() self.resize(600,400) self.mainframe=QtWidgets.QFrame(self) self.setCentralWidget(self.mainframe) self.mainframe.setStyleSheet("background:grey;border-radius:15px;") self.videoframe=QtWidgets.QFrame(self.mainframe) self.videoframe.setGeometry(10,10,580,380) self.videoframe.setStyleSheet("background:

Correct way to close QMainWindow

可紊 提交于 2021-01-29 08:39:17
问题 I recently changed from tkinter to Pyqt5 as I'm developing a semi-large application in Python 3.7.8 Every time I had to close windows I used the method self.destroy() , and there was a small chance that, when I closed all the program and having no windows, the interpreter was still running and I needed to terminate the process manually, even when using sys.exit(app.exec_()) I could had the program running for 15 seconds or 30 minutes, it was completely random. I just saw another method that

How do I stop a custom widget from expanding in PyQt5?

孤者浪人 提交于 2021-01-29 08:35:53
问题 I'm trying to make a widget which contains many other widgets and I keep having problems with resizing the window: the widget keeps expanding even if I "tell" it not to. Here is my minimal example: from PyQt5 import QtWidgets, QtGui, QtCore class CustomWidget(QtWidgets.QWidget): def __init__(self): super().__init__() self.layout = QtWidgets.QGridLayout() self.button1 = QtWidgets.QPushButton("Button A") self.button2 = QtWidgets.QPushButton("Button B") self.label1 = QtWidgets.QLabel("Long label

Resizing custom widget by dragging the edges in pyqt5

我是研究僧i 提交于 2021-01-29 08:06:39
问题 I have made a custom widget similar to QPushbutton or label. I would like to let the user resize the widget when the mouse is over the edge of the widget. How can I do this? (Note: I am not looking for Splitter window) 回答1: An image editing software, you have a dedicated "space" for the image, and the user is free to do anything she/he wants within the boundaries of that space. When a widget is placed within a layout-managed container (as it normally should) that can represent multiple issues

call different window classes into a main window in PQt5 - python

匆匆过客 提交于 2021-01-29 06:50:10
问题 I have a functional code running 2 procedures and display 2 windows separately. each procedure generates its own window. I would like to choose the procedure to be displayed or have both in a main window. the 2 options are of interest. I tried to define a window where i could call each items but since the generation of the individual windows (Mainwindow_1 and 2) belong to a class already defining a window i don't know how to proceed to display only one window at a time upon clicking the

How to change the font and size of image in QTextDocument?

爱⌒轻易说出口 提交于 2021-01-29 06:44:21
问题 I want to print some text and image designed by qtdesigner. How could I change font and another format in QTextDocument ? from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupport class Ui_MainWindow(object): def handlePrint(self): dialog = QtPrintSupport.QPrintDialog() if dialog.exec_() == QtWidgets.QDialog.Accepted: self.handlePaintRequest(dialog.printer()) def handlePreview(self): dialog = QtPrintSupport.QPrintPreviewDialog() dialog.paintRequested.connect(self.handlePaintRequest) dialog