how to sent Information from ComboBox to Python - python

I have a simple code nothing crazy but i just can't figure out how i can sent information from ComboBox to Python. I know the connection between pyton and qml is good, becouse i can sent other strings to python from qml.
Thanks in advance
Funcy.py
#pyqtSlot(str)
def mail(self, dropdown):
print(dropdown) #should print Yes or No
Gui.qml
ComboBox
{
id: dropdown
// those are the options a user could choose
model: ["No", "Yes"]
}
Button
{
// some styling
onClicked
{
backend.mail(dropdown.text)
}
}

If you want to send the selected text from the ComboBox when the Button is pressed then you must send the currentText:
onClicked: backend.mail(dropdown.currentText)

Related

How to implement list of checkable buttons with pyqt

I want to implement list of radiobuttons, but radiobutton shouldn't have a circle and if radiobutton is checked, then the background color is different from the others.
Like in this photo.
(https://i.stack.imgur.com/LsOeE.png)
I think I can use radiobuttons or tabs, but i don't know how to change the styles of this things. Tell me a widget with similar logic or how to change the style of radiobuttons/tabs.
If you don't need the circle of a radio button, then you probably don't need a radio button at all.
Instead, use standard QPushButtons (or QToolButtons) with setCheckable(True) and add them to a QButtonGroup.
win = QWidget()
win.setStyleSheet('''
QPushButton[checkable="true"]::checked {
background: red;
}
''')
layout = QHBoxLayout(win)
group = QButtonGroup()
for title in 'cdefgh':
button = QPushButton(title)
layout.addWidget(button)
button.setCheckable(True)
group.addButton(button)
group.buttons()[0].setChecked(True)
i set css rule:
css = '''
QRadioButton::indicator {
image: none;
}
QRadioButton::checked
{
background-color : red;
}
'''
radioButton.setStyleSheet(css)

Can we call the button using select(A single selection widget) in bokeh?

https://docs.bokeh.org/en/latest/docs/user_guide/interaction/widgets.html (You can see select)
I want to call a button, text input and slider in using select.
plot_button = Button(label="plot")
color_button = Button(label="Color", disabled=True)
axis_start_value_text = TextInput(title=" Start value=", value="270")
axis_slider = Slider(value=0, start=0, end=100, step=1, title="Title")
button_map = {
"plot": plot_button,
"Color": color_button,
"Start value": axis_start_value_text,
"Slider": axis_slider
}
button_call = Select(title="Button call", options=sorted(button_map.keys()),
value="plot")
In the Select button, when I click on a button, text_input and slider the button appears on the screen that I clicked. İs it possible?
I put up an example app on bitbucket.
You can give css_classes to your widgets, or widgetbox, and then access the div elements contaning the widgets in a CustomJS callback.
I have not found a way to set the display to None from the start, couldn't do it with customm css. So I use a timeout function, you'd need to tweak the timing of the timeout function if you don't want the widgets to appear before they are made invisible.
EDIT:
I updated the code, in fact there is a clean way to hide the widgets initially without using a timeout callback. I use a custom css for that with display:none for all objects with class "hidden". Then in the CustomJS you just need to add or remove the "hidden" to the class name of the widgetboxes.

How can i click on a QGroupBox's CheckBox programatically

I want to click on the builtin (enabling) checkbox of a QGroupBox programmatically during testing with pytest-qt.
But i can't find out how to access the underlying checkbox widget of the groupbox via an attribute or similar methods.
Basically i could just use the .setChecked(True) method in my test but this would not be a "real" mouse click.
Is there a to access the checkbox widget of the groupbox directly?
Click action involves pressButton and releaseButton mouse events. So we can emulate click action by sending two sequential events to the destination widget.
Widget::Widget(QWidget* parent)
: QWidget(parent)
, m_groupBox(new QGroupBox)
{
m_groupBox->setCheckable(true);
QPushButton* generateClickButton = new QPushButton("generate click");
connect(generateClickButton, &QPushButton::clicked, [this]
{
clickAt(m_groupBox, Qt::LeftButton);
});
setLayout(new QVBoxLayout);
layout()->addWidget(m_groupBox);
layout()->addWidget(generateClickButton);
resize(100, 100);
}
Widget::~Widget()
{}
void Widget::clickAt(QWidget* receiver, Qt::MouseButton button)
{
if (receiver)
{
QMouseEvent pressEvent(QEvent::MouseButtonPress, receiver->pos(), button, 0, 0);
QMouseEvent releaseEvent(QEvent::MouseButtonRelease, receiver->pos(), button, 0, 0);
QApplication::sendEvent(receiver, &pressEvent);
QApplication::sendEvent(receiver, &releaseEvent);
}
}
Better alternative: QTest::mouseClick does the same

Reacting to a Button Pressed by the user in a EPD Traits view?

I'm using EPD traits for a basic GUI interface. I'm able to pop up a settings window using code like this:
settings_w.configure_traits(kind="livemodal")
The window has 'OK' and 'Cancel' buttons and I want to do something different depending on which button was pressed to exit the window. Seems like it should be simple but I can't figure out how to set this up.
Theoretically I'd like to do something like this:
# Display the settings widget
settings_w.configure_traits(kind="livemodal")
if settings_w.CancelButtonPressed:
pass
else:
print "I got the input"
But let me know if there's a better or more correct way to do this.
Also FWIW: here's the view properties of my settings window with standard OK and Cancel buttons:
view = View(
settings_group,
title = 'Settings Editor',
width = 500,
buttons = [OKButton, CancelButton, 'Help' ],
kind = 'modal',
handler = SaveRestore_Handler()
)
If I understand the question, checking the output of configure_traits should do what you want:
result = settings_w.configure_traits(kind="livemodal")
if result:
print "The user pressed OK."
else:
print "The user pressed Cancel or closed the window."

How to click button in 'alert' message on the webpage with PyQt4

On the webpage, when I create a new user, alert message displayed that 'New user was created'. And in order to continue, I have to click button 'ok'. So the thing is I don't really know how to click it.
when I need to click a regular button I do something like this:
doc = self.page().currentFrame().documentElement()
submit_button = doc.findFirst('input[id=my-submit-button]')
submit_button.evaluateJavaScript('this.click()')
But how to click button in alert message?
You are looking for the QWebPage::javaScriptAlert ( QWebFrame * frame, const QString & msg ) function:
This function is called whenever a JavaScript program running inside
frame calls the alert() function with the message msg.
The default implementation shows the message, msg, with
QMessageBox::information.

Categories

Resources