My code sometimes sets the FocusPolicy of some QLineEdits to NoFocus to prevent data from being entered. When a user clicks on a NoFocus line edit (to try to key in data), I would like to show a message explaining why the user cannot enter data. QToolTip (which is what I would like) does not work because the line edit has NoFocus.
I thought about using mousePressEvent to trigger a tooltip, but am unsure if it would work (because of the NoFocus issue) but even if it would work, am unsure how to code linking the line edit to the function that shows the tool tip. My attempt to code a mouse event (does not work).
self.ui.xyz.mousePressEvent(QMouseEvent=self.check_reminder_tooltips)
Can a message (tooltip or otherwise) be shown when user clicks/hovers over a NoFocus line edit?
If you want the user to not be able to write to the QLineEdit then just set the readOnly property to true:
le.setReadOnly(True)
Related
I'm trying to make a sign up page as part of a mini project I'm working on, and used a checkbutton with a toggle which should generate a username for the user. Upon running, when the checkbox is clicked, my generated username does not output as part of my suggested_username label.
The code can be found at:https://github.com/Gurcharan5/sign_up_program_2022 Any suggestions on where i went wrong?
Tried changing the parameters of the if statements to see if that would change things, and also tested the function using terminal in which it functions as expected.
I'm using pywinauto to interact with the window of an old game - specifically the dedicated server GUI. I've been able to connect to it with:
app = Application(backend="uia").connect(path=r"C:\Program Files (x86)\___.exe")
Using a loop, I'm able to read each line in a Listbox in a specific window using:
for i in dlg.ListBox.descendants():
print (i.window_text())
The Listbox behaves as like a console output area and I've also been able to write commands to the Edit (input) field which appear in the Listbox.
All of this is great considering I didn't think it would be easy at all!
However, the last part of what I'd like to do is proving more difficult...
I want to listen for changes in the list box so I can react to them and write different responses back into the Listbox. So for example, when a player joins the server, I want my code to know that a new line has appeared in the Listbox (so I can write a custom welcome message to the Edit field).
I have tried to look at listener scripts but I feel a bit out of my depth and can't seem to find a simple code example that could help me accomplish this. Does anyone have any ideas where I could look or what I could use?
Even better... would anyone be able to provide some sample code for me to re-work?
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'm doing a python plug-in to GNAT GPS IDE.
It uses the Locations window to shows a messages to the user, therefore highlighting a file line, like errors do. I use GPS.Locations.parse() to add such information, the (somewhat hazy) documentation is here.
The user then could select the line from the code or the Locations window to perform an action.
Get the line from the opened file is a piece of cake.
But one thing that still eludes me, is how I can know which line from the Locations window the user is selecting.
I tried the GPS.MDI.get("Locations") which lead me to a maze of children windows objects. I got lost.
So how can I retrieve the text from the currently selected line in Locations?
Edit
Apparently there MessageContext that would give me what I want, but I get an error message saying there's not such class, even when the window has focus. So I recon that the class wasn't instantiated.
AttributeError: 'module' object has no attribute 'MessageContext'
I only saw this thread now. You should call GPS.current_context(), which will return an instance of GPS.Context or one of its children classes. In this case, you can likely use GPS.current_context().file()
It seems like what you want is to create an entry in the contextual menu in the Locations window. Take a look at the gps_utils.interactive hook. It wraps a python function into a GPS action. This action can then be bound to a specific contextual menu, a keybinding, a menu, a toolbar button,... You can also associate a filter with it, so that the contextual menu also shows up when the action applies (and to implement this filter, you use the above GPS.current_context().file()
I am using a SearchCtrl with a dropdown menu and I'm having some trouble with the events. When I click the little arrow next to the search button, the EVT_SEARCHCTRL_SEARCH_BTN is triggered, which is not what I want. I only want the EVT_MENU_RANGE to be triggered after I clicked an item, and not also the EVT_SEARCHCTRL_SEARCH_BTN before i click it.
self.search_ctrl = wx.SearchCtrl(self.panel_1, -1,
style=wx.TE_PROCESS_ENTER)
self.search_menu = wx.Menu()
self.search_items = {"text1":"value1", "text2":"value2"}
for txt in self.search_items:
self.search_menu.Append(-1, txt)
self.search_ctrl.SetMenu(self.search_menu)
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.search, self.search_ctrl)
self.Bind(wx.EVT_MENU_RANGE, self.onSearchMenu)
Although I should probably add id's to the menu bind, this isn't causing the problem. The code works as expected when I comment out the search button bind.
UPDATE
Apparently this isn't a problem, but a 'feature' of the searchctrl. I tried the wxpython demo and the menu also showed up if I just clicked the search button, and not the arrow. It is apparently one button, instead of the two i thought it was.
Is there a way to accomplish my original request? Do i have to manually modify a textctrl, or is there an other solution?
All the examples I've seen suggest you need to specify a range of IDs when you call your menu bind.
Maybe by default it binds to something unexpected... ?
Edit - In light of your update, it seems likely that you're going to need to make a custom control to me..