I have around 20 QLineEdits on a particular application window.
I want the content of the QLineEdit to be cleared as soon as I click on it.
For a couple of QLIneEdits I use the below lambda function.
self.StudentName.mousePressEvent = lambda event : self.StudentName.clear()
I am not sure how to implement QSignalMapper for this purpose as I have around 20 QLineEdits.
Can someone please briefly explain QSignalMapper.
Will I have to create an array of all the QLineEdit SIGNALs and then map it to the QSignalMapper SLOT.
Please suggest.
As far as I can see, QSignalMapper is for the reverse problem, or collecting and collating signals from multiple inputs.
The simplest way to set multiple events to a simple behaviour is to do it in pure python:
for edit in LineEdits:
edit.mousePressEvent = lambda event : edit.clear()
where LineEdits is your list of widgets.
Related
Qt supports custom paint events for drawing of widgets through QStyle.
However when using the QStyle you need to specify what type of element you're trying to draw,
i.e, if you want a control element you need to paint it by using QStyle.drawControl(CE_Example, style).
My question is, how is someone who is relatively new meant to understand which method to correctly call, or find which element to paint when I want to perform the actions myself, say for example I want to draw my SpinButton with purple up and down arrows. I tried to google and see if I could find an explanation but could not, so I was wondering if this is common terminology or if it was some jargon used by the Qt community.
Any advice for correctly traversing documentation or anything like that appreciated, maybe I have an incorrect approach.
I eventually found my answer traversing https://doc.qt.io/qt-5/qstyle.html#details
Primitive Element: A primitive element is a common GUI element, such as a checkbox indicator or button bevel.
Control Element: A control element is a part of a widget that performs some action or displays information to the user.
Complex Control: Complex controls have different behavior depending upon where the user clicks on them or which keys are pressed.
Exactly how do I utilize the various event methods that widgets have? Say I have a comboBox(drop down list) and I want to initiate a function every time someone changes the choice. There is the changeEvent() method in the documentation but It would be great if someone explains to me with a piece of code.
This is a pretty broad question. I recommend checking out the many tutorials on Youtube.com.
However, in your init method, put something like this:
self.ui.charge_codes_combo.currentIndexChanged.connect(self.setup_payments)
In my example, the combo box was placed on a form in Qt Designer. Self.setup_payment is a method triggered by the change in the combo box.
I hope this helps!
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
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.
I am making a GUI for a script in Python, using PySide Qt. I have a couple of checkboxes in the main window and I was wondering if it is possible to make them dependant to each other. What I mean is that, if I check one of them, all the others should become unchecked. So only one can be checked at a time.
Is there a comfortable way to do this? Otherwise I would just write a function to uncheck the others.
use QButtonGroup to make them as a group and you might want to derive a class from this and override the basic check/uncheck depending on how you want the checkboxes to behave