setlabel in Qlabel will assign a variable in pyqt? - python

I'm still starting out with PyQt with QtDesigner using eric4 (and still studying python as a whole).
Anyway, as I've designed in a GUI using QtDesigner I've just made a Qlabel as a placeholder which is intended to update with the latest ID that has access to a SQLite database which I'm building. I want it to setlabel to change to the next slot available in ID primary key but I honestly don't know how.
I've tried to change the UI compiled form as I noticed that it is this line:
self.ID_Number.setText(QtGui.QApplication.translate("Dialog","IDLabel", None, QtGui.QApplication.UnicodeUTF8))
that sets the label of the supposed ID_Number which would communicate with the SQLite. But I always get a compiling error when I changed "IDLabel" to a variable. I've checked that it is supposed to be a constant but would it be possible that it can be a variable instead? Or am I doing wrong to use a QLabel in QtDesigner and I should use something else?
Any help in solving the wall I'm trying break is very much appreciated bows deeply

The translate function call is used for multi-language support. You can remove it in this case and simplify the code to the following.
self.ID_Number.setText(somePythonStringVariable)

Related

How does Qt Designer work in terms of creating more than 1 dialog per file?

I'm starting to use Qt Designer.
I am trying to create a game, and the first task that I want to do is to create a window where you have to input the name of the map that you want to load. If the map exists, I then switch to the main game window, and if the name of the map doesn't exist, I want to display a popup window that tells the user that the name of the map they wrote is not valid.
I'm a bit confused with the part of showing the "not valid" pop-up window.
I realized that I have two options:
Creating 2 separated .ui files, and with the help of the .show() and .hide() commands show the correspoding window if the user input is invalid.
The other option that I'm thinking of creating both windows in the same .ui file, which seems to be a better option, but I don't really know how to work with windows that come from the same file. Should I create a separate class for each of the windows that come from the Qt Designer file? If not, how can I access both windows from the same class?
Your second option seems impossible, it would be great to share the .ui since in my years that I have worked with Qt Designer I have not been able to implement what you point out.
An .ui is an XML file that describes the elements and their properties that will be used to create a class that is used to fill a particular widget. So considering the above, your second option is impossible.
This concludes that the only viable option is its first method.

PyQt5: Get GL parameters from QtOpenGLWidget without showing first

Is it possible to use GL functions like glGetString without showing the widget first?
The basic use case would be taking this helloworld and instead of showing the widget, maybe I want to print a command line usage message with the GPU information and GL version. The script currently does this already after showing the widget.
In my own application I have a subclass of a QOpenGLWidget and I've tried manually creating a QOpenGLContext, setting the format, and making it current (with and without .create()), but that didn't seem to work. The subclass seems to work fine when shown.
Any help is much appreciated.
Further details: I'm one of the maintainers of the python library vispy and I'm trying to update our PyQt5 backend to use QOpenGLWidget instead of QGLWidget. The pull request is here if anyone wants to tell us what we're doing wrong: https://github.com/vispy/vispy/pull/1394
A OpenGL context needs a "window" (exactly needs a "Device Contex" or a "Display", depending on the OS) to render to. That window doesn't need to be visible, just that the gl context is current to it.
The easiest way is to hide() (or don't call show()) the window at its creation. You can make it visible later.

How to tell when a QTableWidgetItem is being modified

I'm writing an app in Python with the PySide library. I have a QTableWidget that gets updated about every second. The thing is, I want to be able to change the data manually, and I thought that if I could find out whether or not the user is changing the data in the cell, then I could just prevent the program from updating this cell. Otherwise I get "kicked out" of the cell at each update.
Is this a good idea? Should I try something else and why?
How can I achieve my goal?
Many thanks
EDIT :
I know there exists an itemChanged signal, but what I'd really like to know is if there is a way to tell when the user is writing a new value in the cell, in order not to kick them out while editing.
In Qt Document:
void QTableWidget::itemChanged(QTableWidgetItem * item)
This signal is emitted whenever the data of item has changed.
Hope this will help you.
Edit:
QTableWidget uses a default itemdelegate(QItemDelegate instance) which has createEditor method and closeEditor signal.
You can reimplement createEditor which means edit starts, and connect the signal closeEditor which means the edit ends.
This may be the correct way.
Generally, you would handle this situation with the use of QItemDelegates, which allow you to control what cells are editable by the user, what types of controls they are given to edit the cells, and you can catch the data they input and validate or manipulate it before saving it to the model.
QItemDelegates only control edits being made using the view interface. If the table is being updated programmatically, the changes won't be sent to the QItemDelegate.
Here is an example of a QItemDelegate for a QTableWidget

Unable to add checkbox to wxpython GUI during runtime

I am attempting to added checkboxes to a wxpython gui during runtime, but it does not seem to be showing up. My code is below.
I have tried following the post < Add checkbox in wxPython in runtime >, but was not able to get it to work. I also used wxFormBuilder to see how it adds a checkbox during initialization; I was able to verify that self.mainWindow.p_SelectionPanel is where I want to add the checkbox. I have also checked with the debugger to ensure that each line of the code is run at least once.
A little more background about the application: it is a wxPython GUI with a matplotlib plot embedded into it. I am trying to generate checkboxes from an incoming serial port stream so the user can show/hide series during runtime. point is a dictionary with the key as the series name and the series value as the dictionary value.
Please let me know if you need more context.
Thanks in advance for the help.
def addNewCheckBoxes(self,point):
sizer = self.mainWindow.p_SelectionPanel.GetSizer()
addedCheckBox = False
for key in point.keys():
if key not in self.cbList.keys():
self.cbList[key] = wx.CheckBox(self.mainWindow.p_SelectionPanel)
sizer.Add(self.cbList[key])
addedCheckBox = True
if addedCheckBox:
self.mainWindow.p_SelectionPanel.SetSizer(sizer)
self.mainWindow.p_SelectionPanel.Layout()
This issue is cause by utilizing multiple threads; see comments above. I have been able to "hand off" the addition of check boxes to the main thread by using the techniques addressed here: < Sharing data between threads in Python >.
Though, a better, thread-safe way to structure my program is suggested here: < WxPython: Periodically set value in TextCtrl not working >. There is also a way that avoids the use of multiple threads noted, too.

Python widget/cursor detection?

Beginner python learner here. I have a question that I have tried to Google but I just can't come up with the proper way to ask in just a few words (partly because I don't know the right terminology.)
How do I get python to detect other widgets? For example, if I wanted a script to check and see when I click my mouse if that click put focus on an entry widget on a (for example) website. I've been trying to get it to work in Tkinter and I can't figure out even where to begin.
I've seen this:
focus_displayof(self)
Return the widget which has currently the focus on the
display where this widget is located.
But the return value for that function seems to be some ambiguous long number I can't decipher, plus it only works in its own application.
Any direction would be much appreciated. :)
Do you mean inside your own GUI code, or some other application's/website's?
Sounds like you're looking for a GUI driver, or GUI test/automation driver. There are tons of these, some great, some awful, many abandoned. If you tell us more about what you want that will help narrow down the choices.
Is this for testing, or automation, or are you going to drive the mouse and button yourself and just want something to observe what is going on under the hood in the GUI?
>How do I get Python to detect other widgets?
On a machine, or in a browser? If in a machine, which platform: Linux/Windows (which)/Mac?
If in a browser, which browser (and major version)?
> But the return value for that function seems to be some ambiguous long number I can't decipher
Using longs as resource handles is par for the course, although good GUI drivers also work with string/regex matching on window and button names.
> plus it only works in its own application.
What do you mean, and what are you expecting it to return you? You should be able to look up that GUI object and access its title. Look for a GUI driver that works with window and button names.
Here is one list, read it through and see what sounds useful. I have used AutoIt under Win32, it's great, widely-used and actively-maintained; it can be called from Python (via subprocess).
Here are comparisons by the author of PyWinAuto on his and similar tools. Give a read to his criticisms of its structure from 2010. If none of these is what you want, at least you now have the vocabulary to tell us what would be...

Categories

Resources