5

QComboBox - defines the selected element based on the data of the element

 2 years ago
source link: https://www.codesd.com/item/qcombobox-defines-the-selected-element-based-on-the-data-of-the-element.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

QComboBox - defines the selected element based on the data of the element

advertisements

What would be the best way of selecting an item in a QT combo box out of a prefined list of enum based unique values.

In the past I have become accustomed to .NET's style of selection where the item can be selected by setting the selected property to the item's value you wish to select:

cboExample.SelectedValue = 2;

Is there anyway to do this with QT based on the item's data, if the data is a C++ enumeration?


You lookup the value of the data with findData and then use setCurrentIndex

QComboBox* combo = new QComboBox;
combo->addItem("100",100.0);    // 2nd parameter can be any Qt type
combo->addItem .....

float value=100.0;
int index = combo->findData(value);
if ( index != -1 ) { // -1 for not found
   combo->setCurrentIndex(index);
}

Related Articles

Unable to select records based on multiple dates and NULL

I am having some trouble with a query to select the right data from my table. I am trying to find a row of data among dates where the enddate is not null, proving harder than it sounds. My query is this: SELECT ms1.* FROM STATUS MS1 INNER JOIN ( SELE

How to select records based on 2 dates in mysql

i have a table tbl_remit. |RemitNo|id|emp|emp_loc| emp_cat |ap_from| ap_to |amount| | 1 |1 | a | PAL | PRIVATE |12/2015|12/2015| 50.00| | 2 |1 | a | PAL | PRIVATE |01/2016|01/2016|100.00| | 3 |1 | a | PAL | PRIVATE |02/2016|02/2016|100.00| | 4 |2 | b

Define the number of elements in a one-dimensional array based on a variable rather than a constant

I am little confused at to what based on a variable means. I made an attempt at it not sure if its correct. Is it? int size; System.out.print("Enter the array size: "); size = input.nextInt(); int[] arr = new int[size]; Define the number of elem

How can I stylize an HTML selection element based on the number of options it has?

What I would like to do is to change the style of a select box in function of the number of options that it has. More specifically, I would like it to look like a span when there's only one option, and like a typical select element otherwise. In othe

Angular: How to check if the select element is multiple and define a selected option?

An Angular Service, responsible to build URLs from values of select and multi-select elements drives me crazy. A multi-select uses an array to store its selected values, even if there is only one element. { "select006": [ "m30x1.5", &q

Show Hide select options based on the previous selection drop-down list

Thanks for reading my question... ;-) I'm building a Wordpress site that uses Custom Posts and Custom Fields to show a vehicle inventory. I would like the visitor to be able to filter the posts by Taxonomies... The plugin I use for drilling the avail

Obtain the initial selected value of a selected element

I would like to obtain the original selected value of a <select> element as it was written by the initial HTML and defined by selected="selected". For instance, the original value of mySel is 2 no matter what the user selects. Or in other

Style & lt; select & gt; based on the & lt; option & gt;

Is it possible to style a select element based on what option is selected with CSS only? I am aware of existing JavaScript solutions. I tried to style the option element itself, but this will give style only to the option element in the list of optio

How to configure the default in an angular selection menu based on the data binding instead of the index

I would like to set the default item in a select menu based on value rather than by index position. For example, in the sample below, if one of the radio buttons in a form displays "Oranges," and a user selects that radio button, is it possible

Angular adds strange options to a selected element when setting the model value

I have a select element defined as such: <select name="country_id" id="country_id" required="required" ng-model="newAddressForm.country_id"> <option value="">Select Country</option> <o

How to run the function on the 'select` element with javascript / jquery

I am trying to set the default value of a dropdown box which looks like this: <select id="schedule_timeslot" name="timeslot"> <option name="8-10" class="schedule_time" value="0" id="ts0"

Compare a vector with the selected element from a matrix

I want to compare a huge vector with selected element from a matrix in R. A is a matrix and B is a vector. I want to compare each element of B with selected element from A. C and D are selection criteria. They are vectors of same length as B. C speci

Multiselect select element - captures the current set of options before adding / removing new items

Hello and thank you for reading. I have an aspx form hosted in SharePoint 2010 that has some multiple select elements within a form. There are buttons to add and remove options from these select elements. My problem is that I need to run a query base

iOS 6 Mobile Safari made slow of the big table with selected elements

We're building a web application that has a page where the user sees a large table of editable items. This table has controls on each row to move the row up/down and the option to delete the row. Each row also has two select elements. This table coul

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK