How to show Qtreewidget item as in editable mode? means when a data of that particular column will show it should be look like it can be edit.
Means it should be taken data as input.
QTreeWidgetItem *item=NULL;
item->setBackgroundColor(0,color);
item->setIcon(0,coloricon);
item->setText(0,QString(sample->sampleName.c_str()));
item->setData(0,Qt::UserRole,QVariant::fromValue(samples[i]));
**//I want to show this particular column as in editable mode**
item->setText(1,QString(sample->getSetName().c_str()));
item->setText(2,QString::number(sample->getNormalizationConstant(),'f',2));
Related
I understand that the default behavior of LOVs is the following:
SELECT business_desc as display_val,
business_id as return_val
FROM businesses
This attached to a select type page item P1_BUSINESS will display a list and when a list row is selected, then assign the business_id value to the page item P1_BUSINESS.
Is there a way to build a list of values to set the value of more than one page item that are not displayed? Using the below SQL:
SELECT business_desc as display_val,
business_id as return_val,
form_type,
individual_flag
FROM businesses
Where now when a user selects something from P1_BUSINESS it sets the values of that row/record as follows:
P1_BUSINESS = business_id (like it does by default)
P1_FORM_TYPE = form_type (P1_FORM_TYPE is a hidden page item)
P1_IND_FLAG = individual_flag (P1_IND_FLAG is a hidden page item)
I know I can do this with an onchange dynamic action, but just curious if can do inside the LOV or select page item (P1_BUSINESS) declaratively.
In Shared Components > List Of Values, there is an attribute "Additional Display Columns". The help text on that screen says it all Additional display columns can be defined for item types that support multiple display columns, for example the Popup LOV. For item types that do not support multiple columns, these will be ignored. If adding additional display columns ensure that the return column is included in the column list. The return column can be set to Visible No and Searchable No if you do not want it displayed to users.
Example using emp/dept sample data:
Create a list of values on table emp with return empno and display ename. Save.
Edit the LOV and click Additional Display Columns > Select Columns. Select job as additional column.
In the IG, set Visible and Searchable to "No" and Apply Changes.
On the page, create 2 page items: P1_EMPNO (type popup LOV) and P1_JOB (type Text Field)
For P1_EMPNO, pick the LOV created above as shared component > List Of Values and add JOB:P2_JOB under Settings > Additional Output. JOB is the additional column name/alias and P2_JOB is the item it should map to.
Now when you run the page, observe that P1_JOB is populated when you select a value for P1_EMPNO
I'm retrieving a set of results from the database and I want to populate the QComboBox with the resulting columns from the database (each row of the QComboBox should have the same columns as database result) and after that I would like to be able to retrieve from one row of the QComboBox a specific column and use it further in the app. I'm thinking if it would be possible to add the QTableView to QComboBox. I'm want to do this because I want to add more meaning to the results in a way that some result columns are just plain numbers and other are the description information.
I found out that it would be possible to concatenate the result and populate the QComboBox but this will leave me with only one value for each row to work with and I have to explode the string to obtain the exact part that it is needed to work with.
The popup that comes by default is a QListView, this can be changed with any object that inherits from QAbstractItemView, and in this case a QTableView will be used for it to use the setView() method, the result when clicking only should return a item of the selected row, then to set the column to be displayed after being selected will use the method setModelColumn() indicating the position of the column, but before that the model is set to the QComboBox using the method setModel().
# my model
model = new QSqlTableModel;
model->setTable("person");
model->select();
# setModel
comboBox->setModel(model);
# select column
comboBox->setModelColumn(1);
QTableView *view = new QTableView(this);
comboBox->setView(view);
Note: The model is set to QComboBox, not to QTableView. Also you could have problems with the width of QTableView, so we must resize, in my case use the following:
view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
view->setMinimumWidth(500);
The complete example can be found in the following link
The first row is selected by default, when I shift-select the last row I expect that all rows will be selected but no, it only selects the visible rows of the QTableView.
I have a QTableView displaying data from a database-model. It is configured to allow extended selection (ctrl, shift etc) and to select rows only (not cells). The content is changing based on other parameters, and whenever I update the model I select by default the first row of my QTableView.
ui->tableView->setModel(model);
ui->tableView->setColumnHidden(UidColumn, true);
ui->tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
ui->tableView->verticalHeader()->hide();
ui->tableView->setAlternatingRowColors(true);
// This is done whenever the content changes
QModelIndex index = model->index(0,0);
ui->tableView->setCurrentIndex(index);
I hide the vertical headers because nothing to display there, and I hide the first column because it is not relevant for the user.
The first row is displayed as selected, I even logged the changes of focus and the tableView->selectionModel()->selectedRows() is always good (i.e. returning QModelIndex(0,0)). But when I do the shift-click on the last row, it is like the first row was never selected at all.
If I manually select the first row (or any row), the next shift-click will work perfectly. If I do a ctrl-click, the multiselection works perfectly. It is like my default selection (done by the code) is ignored with shift-click.
The default QModelIndex(0,0) selects a cell that is part of the hidden column. Even if displayed as a selected row, apparently it messes up the shift-selection.
If I do not hide the first column, it works fine.
If I use QModelIndex index = model->index(0,1); it works fine.
A simpler solution is to do ui->tableView->selectRow(0);
Extracting text of the selected QComboBox item is well known, but how do I get the text in a QComboBox for an arbitrary index item (not necessarily the one selected)?
Use itemText() method to do this. Just set needed index.
As Marek R pointed, you can get model and get data from this model, but it will be helpful for you when you want to get something more than text( for example get image with Qt::DecorationRole or font with Qt::FontRole)
http://qt-project.org/doc/qt-4.8/qcombobox.html#itemText
http://qt-project.org/doc/qt-4.8/qcombobox.html#model
I have QTreeWidgetItem set in a QTreeWidget with 2 columns. Both cells got a CheckBox set by setCheckState(...).
When the user unchecks the CheckBox in my first column I uncheck the second CheckBox in column 2.
Now, I would like to prevent the user to check this second CheckBox again. Is it possible to remove this CheckBox in column 2 or to disable only this cell?
So far I have just seen that all the flags work on the complete item and a set CheckBox won't disapear.
Btw. The items are not editable and I don't want to use a QTableWidget/-Item.
Update:
The CheckBox will be automatically inserted by Qt when I call setCheckState for the item:
QTreeWidgetItem *item = new QTreeWidgetItem(ui.TreeWidget);
item->setCheckState(0, Qt::Checked);
After the new the item does not own a CheckBox (by Qt default). Calling setCheckState(...) I automatically insert a CheckBox (here in column 0) with the Qt::CheckState I want.
But after I have done it there's no way to remove the CheckBox - so it seems.
Maybe anyone got a solution how I can get rid of this CheckBox at a later time? Any help is much appreciated!
This will do it:
item->setData(0, Qt::CheckStateRole, QVariant()); //No checkbox at all (what you wanted)
any of these others will show the checkbox space
item->setData(0, Qt::CheckStateRole, Qt::Unchecked); //Unchecked checkbox
item->setData(0, Qt::CheckStateRole, Qt::Checked); //Checked checkbox
item->setData(0, Qt::CheckStateRole, Qt::PartiallyChecked); //Partially checked checkbox (gray)
The setCheckState method can not set 'no check state', only Checked, PartiallyChecked or Unckecked.