I need to get the selected value in my qcombobox. It was populated from database, the QCombobox is named cbUser This is my function that populate the qcombobox:
for row in self.SELECT_USERS_ACCOUNTS():
self.cbUser.addItem(str(row[1]),int(row[0]))
The data is showed successfully in the qcombobox cbUser.
and I get a function to will get the value to the selected item:
def getValue(self):
id_us = self.cbUser.itemData(self.cbUser.currentIndex())
print(str(id_us))
The print shows and it's not the data, the correct data is an integer value for example 1 or 2 ....
Please help me, thanks in advance.
UPDATED:
The solution was to modify the first line code into getValue function (add .toPyObject()):
id_us = self.cbUser.itemData(self.cbUser.currentIndex()).toPyObject()
The solution was to modify the first line code into getValue function (add .toPyObject()):
id_us = self.cbUser.itemData(self.cbUser.currentIndex()).toPyObject()
With this I saw the value stored in the qcombobox.
Related
I'm quite new to powerbi developement, and I need your help.
I have a table build from a json :
And I want to add informations to this table, using data from the column "fille".
This cells are fill with 'List'
This 'List' are 'Record' :
And inside this record, I can find my information :
The field that I need is :
For each row of main table
set the value "avancement" of the first 'Record' of the 'List'
How can I reach to do that ?
I'm trying somthing like this, without succes :
tableDev = Table.AddColumn(tableInfoFiltree, "Dev", each tableInfoFiltree[filles]{_}{0}[nom], type text)
I try also to build a function, but, the same, I don't reach to extract the List from the cell to put it in parameter.
Thanks for the help
Try this.
= Table.AddColumn(tableInfoFiltree, "Custom", each [filles]{0}[avancement])
I'm using C++ Builder 2010. I'm wondering, how can I get a value from ListView component? And is it possible get value only from 2-nd column(for instance).
I found a lot of information about adding values to ListView, not reading.
When you add a new item, the TListItems::Add() method returns a TListItem*. To access an existing item, you use the same TListItems to get a TListItem* for the desired item, eg:
// get the desired item by its index in the list...
TListItem *Item = ListView1->Items->Item[index];
In any given item, the 1st column is represented by the TListItem::Caption property, and subsequent columns are represented by the TListItem::SubItems property. So, just like when adding values using SubItems, you use SubItems to read the values, eg:
String value = item->SubItems->Strings[0]; // 0 = 2nd column, 1 = 3rd column, etc...
I'm using a QtableView to display and edit data from a QsqlTableModel.
Everything's fine : data from a postgreSQL table is displayed, and user can edit it and save modifications.
I want to add a row when uses click on a button. I use the insertRecord method from my QslTableModel.
The row is correctly added in the QTableView.
My problem is :
I want to insert a value from a query in the first cell of this new row. (to automatically populate an unique identifier).
This is my code :
def ajoutlgn(self):
query_idNewLine = QtSql.QSqlQuery(self.db)
if query_idNewLine.exec_('SELECT sp_idsuivi+1 FROM bdsuivis.t_suivprev_tablo ORDER BY sp_idsuivi DESC LIMIT 1'):
while query_idNewLine.next():
identifiant = query_idNewLine.value(0)
#print identifiant
record = QtSql.QSqlRecord()
record.setValue(1,identifiant)
self.model.insertRecord(self.model.rowCount(), record)
The value is not inserted in the new row (but if I enter a value by hand, it works perfectly).
Nevertheless, the query is OK (as I can see with the « print identifiant » line, which returns the expected integer).
Do you see what I'm doing wrong ?
Are there other methods to insert programmatically a value in a QTableView cell?
Or do I have to use a QitemDelegate ?
Thanks for advance.
Finally I found the solution :
This line creates a record, but not a record for my QsqlTableModel
record = QtSql.QSqlRecord()
I replaced it with this one, and it works perfectly :
record = self.model.record()
I have problem getting selected rows from QTableWidget. I have table like this:
[id] [ key ]
0 test
1 pass
I want to get every row's key values. I tried QTableWidget->selectedIndexes(); but it says it's protected and I can't access that. When I tried QTableWidget->SelectionModel->selectedIndexes, I don't know how to loop through list and get the key values. Do anyone know better way how can I do it?
Regards.
I'm assuming that you set the selection behavior of your table widget to select rows.
You can always access the so-called "selection model" of any item view/widget. QTableWidget inherits from QAbstractItemView, which gives you access to this special model. This model can tell you the selected rows as a list of QModelIndex, which can then tell you the row. Once you've got them, you can access the table content, in your case the text in the column with index 1 (key column).
static const KEY_COLUMN = 1;
QList<QString> selectedKeys;
QItemSelectionModel *selectionModel = ui->tableWidget->selectionModel();
foreach(QModelIndex index, selectionModel->selectedRows())
selectedIDs << ui->tableWidget->item(index->row(), KEY_COLUMN)->text();
Because you are using QTableWidget, you probably want to be calling selectedItems(). Your results will be based on what you have set the selection behavior to, via setSelectionBehavior()
When you have a list of items, you can specifically get the second column item (if it wasn't selected already):
QTableWigetItem *keyItem = table->item(anItem->row(), 1);
QString val = keyItem->text();
I've searched a lot about the way of getting inedx of selected item of combobox inside datagridview but i have not found it !!
I can get the value of selected item by :
dataGridView1[j,i]->FormattedValue
But i can't get the index !
i've tried to cast DataGridView to DataGridViewComboBoxCell to use (SelectedIndex) property
DataGridViewComboBoxCell ^ t = dynamic_cast<DataGridViewComboBoxCell ^>(dataGridView1[j,i])
but there isn't any propery shown for "t" !
The DataGridViewComboBoxCell does not track the selected index.
You could play with its editing control, DataGridViewComboBoxEditingControl, to get the inner ComboBox, but it will be clumsy.
The simplest thing you can do is to lookup via IndexOf the cell Value in the collection of all possible values you use to initialize the DataGridViewComboBoxColumn.