qwidget

PyQt5 triggering a paintEvent() with keyPressEvent()

断了今生、忘了曾经 提交于 2020-06-26 06:58:08
问题 I am trying to learn PyQt vector painting. Currently I am stuck in trying to pass information to paintEvent() method which I guess, should call other methods: I am trying to paint different numbers to a fundamental block (here drawFundBlock() method, which should draw some lines). The code is trying to check if right arrow is pressed-> drawFundamental block and if number is pressed (now trying to simply draw "5"), it will draw that number on a certain area on that fundamental block. But I can

PyQt: Is it possible to drag/drop QWidgets in a QGridLayout to rearrange them?

旧时模样 提交于 2020-04-16 05:47:13
问题 I am looking for a way to create a grid of graphs that can be dragged/dropped to rearrange the order. My first try was using QDockWidgets as they allow for drag/drop, however they were limited in a lot of other ways. Would it be possible to implement this function in a QGridLayout? For now I have a QGridLayout with 3x3 matplotlib widgets. Here is an example of the desired layout outcome. Sample code: import sys from PyQt5 import QtWidgets from matplotlib.figure import Figure from matplotlib

Qt widget does not receive keyPressEvent

荒凉一梦 提交于 2020-03-05 07:02:15
问题 My child widget does not get keyPressEvents, while if I put the same widget as top level window, it does. I try to set it get focus, but it has no effect on this. Code is below, showing what I try to get to work. #include <QApplication> #include <QKeyEvent> #include <QLCDNumber> #include <QLabel> #include <QVBoxLayout> class DigitSummer: public QLCDNumber { Q_OBJECT public: DigitSummer(QWidget *parent = nullptr) : QLCDNumber(parent) { } protected: void keyPressEvent(QKeyEvent *event) override

Qt widget does not receive keyPressEvent

▼魔方 西西 提交于 2020-03-05 07:01:52
问题 My child widget does not get keyPressEvents, while if I put the same widget as top level window, it does. I try to set it get focus, but it has no effect on this. Code is below, showing what I try to get to work. #include <QApplication> #include <QKeyEvent> #include <QLCDNumber> #include <QLabel> #include <QVBoxLayout> class DigitSummer: public QLCDNumber { Q_OBJECT public: DigitSummer(QWidget *parent = nullptr) : QLCDNumber(parent) { } protected: void keyPressEvent(QKeyEvent *event) override

Qt - How to convert from QObject to UI elements?

╄→гoц情女王★ 提交于 2020-01-30 06:15:08
问题 I am working in Qt 4.7, and I have a QWidget object in my dialog. I need to go through each of the children and extract the current text into a QStringList. Every other object is a QCheckBox, and the rest are QComboBoxes (I would just need the text portion of both). So far the only way I could think of to do this would be to use the children() function to get them as QObject*'s and cast them, like this: QStringList textlist; for(int i = 0; i < ui->myWidget->children().size(); i++) { if(i % 2

Qt - How to convert from QObject to UI elements?

半腔热情 提交于 2020-01-30 06:14:26
问题 I am working in Qt 4.7, and I have a QWidget object in my dialog. I need to go through each of the children and extract the current text into a QStringList. Every other object is a QCheckBox, and the rest are QComboBoxes (I would just need the text portion of both). So far the only way I could think of to do this would be to use the children() function to get them as QObject*'s and cast them, like this: QStringList textlist; for(int i = 0; i < ui->myWidget->children().size(); i++) { if(i % 2

Updating QWidget style after setting it readonly

此生再无相见时 提交于 2020-01-30 05:24:48
问题 I have Qt style sheet ( qss ) for QLineEdit , using different styles for readonly and editable. Works fine, but if I toggle a QLineEdit to readonly (at runtime) the style does not change. Is there a way to force a stylesheet update of such a line edit? As requested, the stylesheet: QLineEdit { background: transparent; border: 1px solid green; border-radius: 5px; } QLineEdit[readOnly="true"] { background: rgba(40,40,40); border: 1px solid rgba(50,50,50); } 回答1: After change edit's state try

Setting background color of PyQt5 QWidget

坚强是说给别人听的谎言 提交于 2020-01-25 21:16:13
问题 I spent some time struggling to use .setStyleSheet to change the background color of a QWidget used as a window, using Python 3.5.2, PyQt 5.9 and Qt 5.9.1. I tried various suggestions I found online, but what ended up working was changing the object name of the QWidget, referring afterwards to that name as an ID in the stylesheet. My question is, is this behaviour I can rely on, or is there an alternative way of doing it? Working code: #!/usr/bin/python3 import sys from PyQt5.QtWidgets import

Setting background color of PyQt5 QWidget

坚强是说给别人听的谎言 提交于 2020-01-25 21:16:09
问题 I spent some time struggling to use .setStyleSheet to change the background color of a QWidget used as a window, using Python 3.5.2, PyQt 5.9 and Qt 5.9.1. I tried various suggestions I found online, but what ended up working was changing the object name of the QWidget, referring afterwards to that name as an ID in the stylesheet. My question is, is this behaviour I can rely on, or is there an alternative way of doing it? Working code: #!/usr/bin/python3 import sys from PyQt5.QtWidgets import

QDialog with rounded corners have black corners instead of being translucent

淺唱寂寞╮ 提交于 2020-01-25 07:04:45
问题 I need to create a QDialog with rounded translucent corners. The problem is when doing so, the corners are translucent, but are somehow filled in by the Window's alpha property making it black (which is my understanding of the cause of the problem) Clearly visible is the rounded edges, but with a black 'background' of sorts. To confirm, this Dialog is a modal dialog launched by a QThread from QMainWindow . It is not the parent window . The CSS for the QDialog (root) component is: QDialog {