pyqt

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

Embedding native windows inside QDockWidget

醉酒当歌 提交于 2021-01-29 08:48:04
问题 I am trying to take a native window from an other process and manage it as a docking widget in my process. This is very similar to: How to manage separate GUI processes in a Qt application? I have found the following which gets me pretty far: https://gist.github.com/torarnv/c5dfe2d2bc0c089910ce Problem is the dock window size does not match the size of the contents it's wrapping (there is a margin which it about 15px wide and 40px tall (see pictures for examples)). from PyQt5 import QtWidgets

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

How to insert and clear placeholder in QTextEdit

给你一囗甜甜゛ 提交于 2021-01-29 04:17:10
问题 I have a QTextEdit with setText() already but I want a the placeholder to clear when user selects the Edit Text. Illustration shown here 回答1: The placeholderText property only exists from Qt 5.2 so I have implemented the same logic for PyQt4: from PyQt4 import QtCore, QtGui class TextEdit(QtGui.QTextEdit): @property def placeholderText(self): if not hasattr(self, "_placeholderText"): self._placeholderText = "" return self._placeholderText @placeholderText.setter def placeholderText(self, text

PyQt5 Gui Thread to worker Thread signal/Slot

浪尽此生 提交于 2021-01-29 01:51:07
问题 I am trying to make a simple communication between a worker thread, in this case it is called WorkToDo via the PyQt5 Signals and Slots mechanism. I can reliably send data from the Worker to the Gui thread via this mechanism, but I cannot do the same to the gui thread. From my research I have found that this is due to the fact that I have overridden the run function with my own logic. My question, is there any way to manually handle the execution of signals in the worker thread? Is there a

PyQt5 Gui Thread to worker Thread signal/Slot

给你一囗甜甜゛ 提交于 2021-01-29 01:47:38
问题 I am trying to make a simple communication between a worker thread, in this case it is called WorkToDo via the PyQt5 Signals and Slots mechanism. I can reliably send data from the Worker to the Gui thread via this mechanism, but I cannot do the same to the gui thread. From my research I have found that this is due to the fact that I have overridden the run function with my own logic. My question, is there any way to manually handle the execution of signals in the worker thread? Is there a