In R shiny, a dropdown widget shows itself when it is updated - r

I can't produce an example because the code is pretty large and complex.
But there is a selectInput widget that is hidden, via shinyjs::hide. But when I call the updateSelectInput function to change the values of this widget, it shows itself.
Has anyone encountered a situation like this? Just by merely updating the widget should not cause it to reappear.

Related

How to figure out the index of a ToggleGroup's selected toggle?

I'm trying to select an item from a list that's sorted the same way as a ToggleGroup I have besides it. However, I found that toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle()) always returns -1 (visible in the IndexOutOfBoundsException thrown as I pass it). Is there another way of figuring out the index, or am I at a loss with my approach and need to figure out something completely different?
UPDATE: Apparently, for the first time an item is selected (I have this code attached to changes of selectedToggleProperty()), it works fine (I just get no notice of it because the elements I make visible have no proper layout). However, when an item is selected while another item already is selected, getselectedToggle() becomes null, causing aforementioned behavior.
All of the JavaFX toggle controls have a property called UserData. You should use that to create the links between the toggles and data list. Relying on the index of the toggles in the toggle group is probably a bad idea.

Bar Chart in JavaFx

I'm new in JavaFx and i want to display a Bar Chart after choosing a date (for the SQL query) and clicking the button "display chart". I'm wondering if it is possible to display the chart in the same Tab Pane where the button is. What should i write in my button listener? Can anyone help me?
If this is possible, i want also to use the progress indicator while waiting for the result.
I'm not going to write the code for you, but I'll try to address some of the questions you raised.
I'm wondering if it is possible to display the chart in the same Tab Pane where the button is.
Yes, that seems to be what the sample image you provided is already doing.
What should i write in my button listener?
The code to fetch the chart data and display the chart. If you have trouble writing this, you should create an mcve which replicates just the specific thing which is going wrong.
If this is possible, i want also to use the progress indicator while waiting for the result.
See the sample code here, which is a "Sample for accessing a local database from JavaFX using concurrent tasks for database operations so that the UI remains responsive." The sample makes use of a progress indicator.
Aside: For future questions, you might benefit from just asking a single question in a question, providing some source code which replicates any issue you have, subdividing your problem into parts and asking a specific question on just one particular part you are having an issue with (for example displaying items in a bar chart could be a different question from asynchronously retrieving items from a database).

Automatic database update when widget is reopened

I have a widget that sits within a stacked widget and is used to display a database in a table. At the moment the database is populated and displayed within the constructor which is wrong as it only happens the once so never updates. So I am guessing there has to be a function that should be called for database updating.
So I am hoping there are functions that can be overridden for when widgets are closed or opened? But I am not sure what these are. I am sure it is something really obvious but I'm not having any luck finding them
So I am hoping there are functions that can be overridden for when
widgets are closed or opened?
showEvent(QShowEvent* event) and hideEvent(QHideEvent* event). There is also a closeEvent(QCloseEvent* event), but that probably isn't applicable for widgets in a stacked widget.

Show Editors for All Cells in Row in QTableView

I would like to display editors for all cells in a row when a user begins editing any cell in a QTableView. I have made several attempts but I cannot obtain the correct behaviour.
The only way to open multiple editors is by QAbstractItemView::openPersistentEditor() - attempts to successively call QAbstractItemView::edit() results in only one editor.
I cannot use signals such as clicked() and doubleClicked() from QAbstractItemView to invoke editing, because then it would not respect the edit triggers of the view.
There appears to be no "editing complete" signal. I would like to connect this signal to a slot that calls closePersistentEditor() for cells in the editing row.
Any suggestions would be appreciated.
Thanks!
I hate to be the bearer of bad news, but I can't think of any easy way to do what you want. I can think of a couple of options, each more painful than the last:
You could create a delegate that always shows the editors, and when the user changes the selected row, set that delegate for the newly selected row, and the original delegate for the deselected row.
You could try inheriting from the table view, and overriding the behavior for drawing the appropriate items for everything in the given row. I have no idea how hard this would be, but I doubt it would be trivial.
You could create your own view to display the model. I've never done this, and I'd hate to think about all that would be required to "complete" support the models. However, to match with one specific model, you might be able to get away with it.

How can I tell a QTableWidget to end editing a cell?

I'm showing a popup menu to select some values in a QTableWidget. The lowest item is a "Modify list" entry, when I select it a new window should automatically appear and the QComboBox should vanish and the cell return to a Qt::DisplayRole state.
Now Qt has all those nice API-calls like QTableWidget.edit() and QTableWidget.editItem(), what I'm really looking for is a QTableWidget.endEditing(), preferably without specifying the index of the cell, though I could get that using this call:
table.currentIndex()
… but I don't know if I can guarantee that the current cell is the cell being edited at all times.
Is there an API to close those kind of editors?
QTableWidget inherits 19 public slots from QWidget. One of those is setDisabled(), which should disable input events for that widget and all of its children.
I would try:
table.setDisabled( true );
table.setDisabled( false );
Although you said it does not work for you, there is an alternative method:
If you don't like that (the table loses focus, I believe), you can try using EditTriggers. For example:
table.setEditTriggers( QAbstractItemView::NoEditTriggers );
table.setCurrentItem(None) is what worked for me. (Don’t forget to block signals if you use some cellChanged/itemChanged slot function.)
This is with PyQt. For C++ I think replace None with NULL.
You may be able to use QTableWidget.closePersistentEditor() to close the editor. However, QAbstractItemView.closeEditor() may be closer to what you want, especially since you seem to be comfortable with the QModelIndex-based API and are already using a custom editor widget.
In my case, none of the options worked properly. So, I figured: I need to send the key press event to the line edit itself. The following works with QTreeView but probably does work with any other view or widget that opens a line edit to edit cells.
QWidget* editingWidget = treeView->findChild<QLineEdit*>();
if(editingWidget)
{
QKeyEvent keyPressEvent(QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier);
QApplication::sendEvent(editingWidget, &keyPressEvent);
QApplication::processEvents(); // see note below
}
In my case, I wanted to start editing another field directly when having finished editing one item. That is why I put processEvents there, in most cases you can probably remove that line.
PS: yeah, it's C++, but should be easily adaptable to Python. I found this thread when I searched for the C++ solution, so maybe it helps anyone else, too.
I can't speak for list widgets. But, I got here trying to do something similar.
I was double-clicking a cell, and based on the column, bringing up a sub-form with a list, then when that was closed move to the next appropriate column based on the value selected.
My problem was I could get the value in the cell and "select" the next appropriate cell, but the original cell stayed selected in edit mode!
It finally dawned on me that my double-click was selecting the cell, ie. editing.
A single-click selects the cell but doesn't open an edit mode.
Side note: Never could get that sub-form to act truly modal, so I created a loop in the calling form: while the sub form was visible, with the only code being app.processEvents()

Resources