pyqt5 | PyQt5 from riverbank
kandi X-RAY | pyqt5 Summary
kandi X-RAY | pyqt5 Summary
SIP 4.19 source code in tarball directory. for pyqtdeploy use pip.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of pyqt5
pyqt5 Key Features
pyqt5 Examples and Code Snippets
Community Discussions
Trending Discussions on pyqt5
QUESTION
I am trying to use beginMoveColumns
to move a single column over in a QTableView
, but it doesn't work properly in my example below. The cell selections get shuffled and column widths don't move. Moving rows using the same logic seems to work correctly. What am I doing wrong?
ANSWER
Answered 2021-Jun-15 at 20:13Turns out it was a bug, I made a bug report here: https://bugreports.qt.io/browse/QTBUG-94503
As a workaround I just clear cell selection on column move, and use this snippet to move column widths
QUESTION
I've started to create UI tests for my PyQt5 widgets using QtTest but have run into the following difficulties:
In order to speed up things, some of my widgets only perform operations when visible. As it seems that QtTest runs with invisible widgets, the corresponding tests fail.
For the same reason, I cannot test program logic that makes a subwidget visible under certain conditions.
Is there a way to make widgets visible during test? Is this good practice (e.g. w.r.t. CI test on GitHub) and is QtTest the way to go?
I have tried to use pytest with pytest-qt without success as I couldn't find a proper introduction or tutorial and I do know "Test PyQt GUIs with QTest and unittest".
Below you find a MWE consisting of a widget mwe_qt_widget.MyWidget
with a combobox, a pushbutton and a label that gets updated by the other two subwidgets:
ANSWER
Answered 2021-Jun-15 at 17:01The problem is simple: QWidgets are hidden by default so isVisible() will return false, the solution is to invoke the show() method in init() to make it visible:
QUESTION
How to get the return value? Attach my code. My intention: Want to check the QListWidget and if it's empty, a message Box popup will raise and ask the option from the user. Problem: At the stage of beginning itself, a Message box popup will display, (I don't want it at the beginning stage), If the QListwidget is empty then the MessageBox popup will display as desired, and if we select "Yes" or " No" Button, Nothing will return/print in the first file. How to resolve?
Main
...ANSWER
Answered 2021-Jun-15 at 16:49In first it is not necessary to make the verification be done in a new class, it is also logical that you invoke func_create_newitem since as you point out that method must be invoked when the item was not found.
QUESTION
I have a python code that I can add multiple rectangles on a QGraphicsScene.
...ANSWER
Answered 2021-Jun-14 at 18:46There are several options:
setBackgroundBrush():
QUESTION
What my code is about: I'm currently working on a project to create an image browser for all the images I have in my PC. I have created a database of all the images, this app will give me the ability to search through the database to find, and view and cycle through the images.
What my problem is: I'm trying to read left and right arrow key presses and connect them to a function that will change the shown image to the previous or next image in sequence. But for some reason the first two left-arrow presses don't register and none of the right-arrow presses register. Also, no other key presses are registering. My guess is that this is happening because the arrow keys are cycling through the widgets on screen. Need ideas on how I can fix this.
...ANSWER
Answered 2021-Jun-14 at 17:19The main problem is that you're adding widgets that can get focus, while the "viewer" doesn't have a focus, nor it can accept one by keyboard/mouse if not programmatically.
The result is that when the window is shown the first time, Qt will try to set the focus on the widget that can accept one within the central widget, but since there's none, any keyboard event is ignored. Whenever you try to use the arrow keys, then, Qt will use the "keyboard navigation" mode, and will find the first widget that can accept focus (the "search" button, if you go left), making the event accepted, and thus not propagated to the main window; going further, if you go left once more, the "tags" combo will get focused, again accepted and not propagated.
A temporary workaround could be to ensure that the buttons and line edit only get focus by clicking (but buttons should probably not get focus at all):
QUESTION
My GUI is able to play videos automatically when selected in the QListWidget
. However, instead of normal speed, the videos play very fast. I use 720p Mp4 videos as examples and are placed in a certain folder. I tried using cv2.CAP_PROP_FPS
and cv2.CAP_PROP_BUFFERSIZE
, but they are both not working. I am using pyqtSignal
in the QThread
and the convert_cv_qt
function which I saw in other guides. How do I play the videos in normal speed / frame rate?
ANSWER
Answered 2021-Jun-14 at 10:44When you use VideoCapture with a file if you call "cap.read()" you will obtain the next frame on the video, regardless of its actual framerate. Hence, you should use a "msleep" every time you capture a frame:
QUESTION
How can I create a new file using file dialog with pyqt5? This is my code so far, it prints out the correct path after I create the new file but it doesn't actually create it
...ANSWER
Answered 2021-Jun-13 at 20:15def newFile(self):
name = QtGui.QFileDialog.getSaveFileName(self, 'Save File')
file = open(name,'w')
text = ""
file.write(text)
file.close()
QUESTION
I want to change the color of selected item in QListItem, and I find qss may be a solution. And the code is:
...ANSWER
Answered 2021-Jun-13 at 17:22The problem is that you're setting a QWidget for the item, and since you're using a universal selector (with the wildcard), the result is that all QWidget will have that background color, including those added as item widgets for the list view.
The color you used for the :selected
pseudo is only valid for the item painted by the view, since the item widget has its own background set from the universal selector, that background won't be visible.
The solution is to use a proper selector combination ensuring that the rule only matches children of the list view that have a usable selector, and set a transparent color for those widgets.
A possibility is to set a custom property for the widgets that must be set before adding the widgets to the list (otherwise, you need to set the stylesheet after adding them, or request a style.unpolish()
).
QUESTION
I display an image within a custom QLabel
and get clicks on this label. I'm interested in clicks within the image only, and in a position expressed by a number between 0 and 1, 0 being the leftmost or topmost pixel and 1 the rightmost or bottommost pixel, regardless of the image actual size.
I can't get the image rectangle to compute the position. When I call self.pixmap.rect()
, width and height are the original image dimensions, not the dimensions of the image which was scaled to fit into the label.
What am I doing doing wrong?
...ANSWER
Answered 2021-Jun-12 at 17:16You have to use the QPixmap established in the QLabel that can be obtained through the pixmap() method. The problem is that you are obfuscating the access to that method since you have an attribute with a similar name. So the solution is to use pixmap()
and rename the attribute pixmap
.
QUESTION
I have made a GUI application using PyQt5 module for my Unit converter for Time(Meaning converts the units of Time like seconds to milliseconds, minutes to milliseconds, etc) using a QtDesigner. But the only problem I am facing is that I do not know where and how to input the function of my application to make it work as a unit converter for Time. Below is the full code of my GUI application:
...ANSWER
Answered 2021-Jun-12 at 03:00Qt uses a concept called "Signal/Slot mechanism".
Every Qt object (QObject, which is inherited by all Qt widgets) is able to "emit" signals with a (possibly empty) amount of arguments, and that signal can be "registered" to slots, which are functions that will be called everytime that signal are emitted.[1]
A typical case is a button (normally, a QPushButton), which has a clicked
signal[2] that is emitted whenever the button is clicked, meaning that the mouse cursor is over the button both when the mouse button is pressed and then released.
Every Qt widget has different signals depending on its purpose.
For instance, the QLineEdit control has a textChanged
(that is emitted whenever the text is changed, even programmatically) and textEdited
(which is only emitted when the user actually types something in it).
A QComboBox has the currentIndexChanged
signal, emitted whenever the current item is changed (for instance, opening the popup and selecting a different item, or by using the mouse wheel over it).
In the following code, I'll be connecting to "slots" (in this case, simple python functions) by completely ignoring the arguments of the related signals, but there are cases for which those arguments are actually needed.
The idea is that whenever the user types something in any of the line edit fields, the related function tries to convert the typed value to a numeric one, and then, based on the current content of the comboboxes will do the proper conversion.
Consider that:
- QLineEdit is not a suggested control for numeric input. A QSpinBox (for integers, otherwise a QDoubleSpinBox for floating points) is more suited for such situations; alternatively, setting a QIntValidator or QDoubleValidator on the line edit is possible.
- Using
combobox.addItem()
allows setting user data for each item along with the visible label; I'm using that "hidden" data by means ofcurrentData()
for multiplicators that are used for the conversion; this also means that you should remove any existing item for those comboboxes from the UI in Designer. - Editing files generated by
pyuic
is considered bad practice (for a lot of reasons); I strongly suggest you to carefully read the official guidelines about using Designer, generate again the files from the UI and never touch them again (unless by overwriting with pyuic): those files should always be used as imports only. In the following code I'm assuming you've updated your UI (by removing the items in the first two combos) and converted them again to a file namedunitConverterUi.py
, which will NOT be the actual script you'll be running. - Using fixed geometries (manually positioning and resizing widgets) is rarely a good idea. Remember that what you see on your screen is almost always never what others will see on theirs. Read more about layout managers and how to use them in Designer. User interfaces should be able to adapt to the screen and system settings of the user (what is called "responsive design" in modern website design).
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install pyqt5
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page