qt listwidget clear() unexpectedly trigger itemSelectionChanged() - qt

in PyQt(Pyside6), I created a QListWidget:
it shows 3 items of '1/2/3' when I click one 'show_123' Button
it shows 3 items of 'a/b/c' when I click one 'show_abc' Button
when I click '1' in the QListWidget, one Label shows '1'; click '2', shows '2'; click 'a' show 'a', etc
the 'show_abc' button simple code is as bellow, ('show_123' is similar)
listWidget1.clear()
listWidget1.addItems(['a','b','c'])
and pseudo code for updating Label is
listWidget1.itemSelectionChanged.connect(update_label)
BUT, I found the "listWidget1.clear()" will trigger "listWidget1.itemSelectionChanged", so to call update_label. This is unexpected, I just want to 'clear&addItems' to refresh. how could I solve this problem

I added "setCurrentItem(None)" before clear() to solve it, not found some more elegant way.
listWidget1.setCurrentItem(None)
listWidget1.clear()
listWidget1.addItems(...)

Related

Trying to set up a keyboard shortcut of a button inside a webpage and press it multiple times

My work is to watch videos, select some options and then press the "Submit" button. The thing is that the options I have to select are on the left side of the webpage and the "Submit" button is on the right side. I think I will be able to do my work faster if I can make a keyboard shortcut to press the "Submit" button. I somehow built this code
var button1 = document.getElementById("_SSsubmit");
window.addEventListener('keydown', function(e) {
if (e.altKey == true && e.keyCode == 83)
button1.click();
});
I put it in Chrome's Developer Tools Console and it works only 1 time. The next time when I press "Alt + S" - nothing happens. Is there a way I can make it work while the tab is opened?
The event listener itself will trigger multiple times so long as the page isn't reloaded, you can test this by replacing the button1.click() with a simple console.log(). It seems to me that either:
a) the page is being reloaded every time you submit, in which case you would need to paste the code into the console every time the page loads or
b) the submit button element is getting replaced with a new element each time, in which case you would need to re-assign button1 every time. Most likely, the page is being reloaded.
In either case, your best bet here is probably writing a small Chrome extension so that you won't need to keep pasting code into the console.

JavaFX uneditable combobox - strange reaction on DELETE keystroke

Preamble
I have uneditable combobox (user can select from list, but can't type). I suppose, when user have focus on it and press DELETE, it's selection must be cleared? It seems that it is (screenshot was made when I selected some value and then pressed DELETE):
selectionModel is null - screenshot
Problem
But UI control still shows old value, it wasn't cleared. Also ValueChanged listener wasn't triggered.
How to cause
Create ComboBox and fill it with some values. Select any value. You already have selection on it, but it's not enough - now DELETE pressing won't even clear selectionModel. The same with selecting by TAB. Select it with double click (expand and collapse) and then press DELETE. Now selectionModel must be cleared, but UI still show your value.
Another thing: if you closed ComboBox, pressing DELETE will trigger ValueChanged listener. Pressing DELETE on expanded ComboBox won't trigger it, but nevertheless value will become null.
Did anybody face with this? Any ideas to make it work naturally i.e. clear selectionModel and update UI?
Well, the problem was not exactly where I thought. "Delete" button did nothing in any case, ComboBox was cleared because it's items list was refreshed every time when it was expanded -> old items were deleted including selected. Problem was the same - UI wasn't updated. So I resolved this by adding ComboBox.getEditor().clear() before refreshing it's items list in onShowing event.

Need help troubleshooting button click in Selenium

Update:
After further investigation, actually what's happening is when the checkbox is checked using jquery, the next step is to click the button to save. Well, for some unknown reason, the checkbox is unchecking itself.
Here's the jquery to select the checkbox:
string jsStmt = #"
$(function(){
$(':checkbox').filter(function(){
return $(this).parent().next('td').text() === 'Label to look for';
}).prop('checked', true);
});
";
IJavaScriptExecutor js = (IJavaScriptExecutor)_driver;
js.ExecuteScript(jsStmt);
I can see the checkbox get checked, then when the dialog closes I can see it get unchecked?
OP:
Button click event for Selenium testing has been working for a while. All of a sudden, it's not working anymore. Only possible change was some 3rd party css change but I don't know what it could've been.
The button is kind of buried in layers, however, there's a checkbox that gets checked by Selenium that is still working fine, and it's the reason why the button needs to be clicked.
I can debug, and see that Selenium is finding the button. It appears that the button gets clicked but the postback event doesn't occur.
I can stop execution right before the click event and open developer tools and manually type in the statement to click the button, AND that works!
I even tried executing the click with JavaScriptExecutor with no luck.
I am so lost why it's Not firing postback event.
In short, try clicking the checkbox using an IWebElement instead of javascript.
I would suggest avoiding using IJavaScriptExecutor as much as possible in selenium tests as it can lead to performing functions the user wouldn't actually be able to do with simple interactions, or having those functions behave differently than you would expect because the execution path is different than what a user would do if they just clicked something.
I think that's what you're running to in this case where you're trying to mark the box as checked.

No event getting generated on button click in MFC

I have a dialog based application. I have one static text control and a button on this, both of which I have made invisible in the beginning. I want to show both the controls on reaching a certain condition. When I click this button, again I want to make both the controls invisible.
However, I am able to show and hide the control and also captured the button click event like this:
ON_BN_CLICKED(IDC_MY_BUTTON, &MyDlg::OnBnClickedMyButton)
and defined OnBnClickedMyButton().
But when I press the button, it is not pressed and the event is also not generated.
Any suggestions?
First check if the IDC_MY_BUTTON exists and is valid.
Remember to add DECLARE_MESSAGE_MAP() at the header file.
Also check at the BEGIN_MESSAGE_MAP(MyClass,MyParentClass) if the class
and the parent class you write are right.
I hope this helps.
I think the IDC_MY_BUTTON maybe is invalid or other control has the same ID.
Well, finally I have come to know that though the button was visible but on clicking it was not taking control, hence I used BringWindowToTop() to draw it on top. Now it is being clicked and OnBnClickedMyButton() is also being called.
But now the issue is that after calling BringWindowToTop() the button is not shown. It is shown only when I take the mouse pointer on it. Not able to understand what is the issue.

Application Crash problem on second time click on Menu Arrow of QToolButton

In my APPlication I have to show filter option (as filter option in xls)in Qtable widget for this
I have used tool Button( with property "QToolButton::MenuButtonPopup") to display Menu List and
Upon First Click upon Menu arrow it should show Menu list and selection of any of the Menu it should show only row having the text.
This functionality works fine.
But if Nothing is selected from Menu list and user has clicked Menu arrow second time then list should be hidden but in my case
application crashes giving error:
ASSERT failure in QList::operator[]: "index out of range", file ........\Qt\2010.04\qt\include/QtCore/../../src/corelib/tools/qlist.h, line 447
I have written below code:
QToolButton *lToolButton = new QToolButton();
lToolButton->setPopupMode(QToolButton::MenuButtonPopup);
lToolButton->setAutoRaise(true);
lToolButton->setText("Filter");
QMenu *lMenu = new QMenu();
QAction *lAction = new QAction("All",this);
lMenu->addAction(lAction);
lToolButton->setMenu(lMenu);
Please let me know what is wrong in my coding.
Can you run your app in the debugger and find at what line in your code (not in Qt's code) the error is happening? The problem should then because more obvious.

Resources