JavaFX combo box start value? - javafx

I was curious if there is a way to set a start value for a combo box so that it does not start at the topmost value. For example, I have a combo box called cbCurrentWeight with values ranging from 10 all the way to 999. I don't want 99% of users to have to scroll 100-200 numbers so they can select their weight. I would like for the combo box to start at 100 with the option to go higher or lower from there.
I do not want to set a default value for this combo box either.
Would I be better off just using a TextField and adding parameters to ensure users are entering a valid number?

If you'd like to go the simple route, a TextField with input validation is probably best.
Another thing you could do is create your own version. Where you display the number 100 with a (+/-) button next to it and every time a user clicks the button you increment/decrement the value. You can even add a TextField for step size so users can increment by 20lbs or 5lbs at a time.

I decided to simply change the value to a minimum of 50lbs. The spinner option was great though, and I got it to work. I just prefer the view of the ComboBox.

This is absolutely doable, here is the code:
combo.getSelectionModel().select(90);
This would have the combo box set itself to the 90th option. Assuming you have values 10-999 in order, this would make your combo box set itself to the 100 option.
When you call
combo.getSelectionModel().
Here are the different ways you can modify a combo boxes selection: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/SingleSelectionModel.html

Related

is there a numeric Qt edit box with more than one spinner?

Before i embark on developing a custom control i wonder if somebody would know of a QT control consisting of an edit box (for a number) with more than one spinner next to it. One spinner would be used to increment/decrement the number by 10's, the other by 1's. Ideally, one could allow even three spinners (for the 100's).
There is no standalone spinner but i'm thinking maybe putting several small scrollbar controls next to each other would do.
I highly doubt that there is such a control.
Note however that a default QSpinBox supports incrementing/decrementing in steps of 10 by pressing the Page Up or Page Down keys on your keyboard.
Thanks for the tip!
I ended up creating a horizontal layout with 0 spacing, then placing three QDoubleSpinBox instances in it. On the second and third i set the max width to 15 to just show the spinners. Visually it looked great: an edit box with three spinners.
I then connected the value changed signal from the first to the second and third and the value changed from the second and third to the first. So then clicking on any of the spinners changed the value on the first correctly. Finally, i adjusted the stepsize on the spinners as needed.
It was a lot easier than what i thought it would be.

How to highlight a row in QTableWidget?

I'm having a QTableWidget with 9000 data. I can search data from the table, like, if I search for '10', whole data starting with '10' will be displayed.
Now I need to highlight the first row, since it shows the accurate search result.
I'm using:
ui->tableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);
for highlighting the selected row.
How can I highlight the first row of table?
I am not sure I am clear of why you need to set selection behavior unless you are planning for the user to be able to do the selection by clicking on the cells. And if you want that to be the default behavior then just set this as a property of the tableWidget when you use the QT designer.
But you can certainly do:
ui->tableWidget->selectRow(0);
That will highlight the row.

How to show only 30 rows and hide the remaining rows of QTableWidget

I'm having a QTableWidget with 10,000 records. I need to show only 30 rows at a time and hide the remaining rows. While dragining/clicking vertical scrollbar it should show corresponding rows and hide the other rows.
ie, if one clicks on upper scroll button it should show one more upper item and hide one lower item and vice versa. It should happen while scrolling as well.
Can anyone help me in doing this?
I think you can trap the events of up/down buttons as Nicholas said, for the tracking of slider/scroll bar u need use 'setTracking(true)'followed by the handling of signal either 'valueChanged(int)' or 'sliderMoved(int)'.
Thanks,
Pradeep
Qt unfortunately won't make this easy for you, there is ways and means of doing it however. Depending on how you're populating your widget I'd recommend setting it up so you initially populate your 30 rows, you then need to trap the signals coming from the scroll buttons being clicked and tell the table widget to remove the upper/lower item and add the next one, there's trade off's to this method, but it'll make it easier than trying to maintain a large list of hidden rows.
I don't know if explicitly showing/hiding things is the way you want to go. Instead, take a look at Qt's model and view classes. If you are using a database, have a look at QSqlTableModel, which should handle these things for you. Otherwise, have a look at the Model-View programming document, their related examples, and especially the portion about optimizing for performance (although in a model, 10,000 records isn't really all that many for most uses).
There is a way to change table scrolling from pixels to items. In Designer Property Editor for the table, in the QAbstractItemView section, there is a VerticalScrollMode selection. This can either be ScrollPerPixel or what you probably want, ScrollPerItem.
That may change the behavior of the signal from pixels to items which would make your calculations easier.
I'm using 4.4.3.

ASP.Net Cannot tab through all radio buttons when selected

I'm trying to implement accessibility (keyboard only) ability on my site, but I'm having problems with Radio Button lists. When using radiobuttonlists, when initially, none of the radio buttons is selected, I am able to tab through every single value and select one upon hitting "enter". However, after a value is selected, I can only tab to the selected values, which presents a problem if I want to change the selected value.
From what I understand, radio buttons are grouped at the container controller level, thus when it is considered a group, only one can be selected at a time.
Any ideas on how to fix this issue?
Actually, this is not an issue at all. If a value is not selected, the browser will go through each value within the group. Once a value is selected, the browser will only jump to the chosen value within that group. Thus to change values within the group, the user is to use the keyboard arrows.
I believe you're correct about the RadioButtonList being one control (and therefore tabbing doesn't work). An alternative could be to create individual radio buttons and use the GroupName property to assign them all into one group. This should let you tab between them and still ensure they work in sync with each other.

ASP:ListBox | Multi Select | Keep selected values when selecting a new one

1) Have a listbox with 3 values out of 5 selected
2) When I click to select another value without holding CTRL button, it will unselect over values
How to make it keep other selected values if new value is selected?
This is going to sound like a snide answer, but I don't mean it that way. I just like to look for the simple solutions rather than the complicated onces.
The easiest way to get a control to have the behavior you want is to use a control that has the behavior that you want, rather than modifying the behavior of an existing control.
That said, if you want a list of items where a user can select a bunch of items off the list, and don't want to have to rely on them holding control, you're using the wrong tool for the job.
Use a CheckBoxList instead of a ListBox. If you want it to be scrollable, then set it in a div of a specific height, and set the style of the div to "overflow: scroll".
If you still want to use a ListBox you should use javascript and for each click event fired, you should check if the clicked element is selected/unselected and act accordingly. It's a little bit tricky but at least it is a solution for your problem.

Resources