Accessing the contextMenu of a spark TextInput component - apache-flex

How can I add custom context menu items to the context menu of a spark TextInput component? I am using Flex 4.5.1.
Assuming I have a spark TextInput called sparktext:
trace(sparktext.contextMenu) // returns null
trace(sparktext.textDisplay.contextMenu) // returns null
Since those returned null, I though I would just create a contextMenu using:
sparktext.contextMenu = new ContextMenu()
//add entries
Or
sparktext.textDisplay.contextMenu = new ContextMenu()
//add entries
Now a contextMenu is created. But the created context menu is a "flash" context menu, displaying items like "play", "zoom" and so on. I have lost entries for items like "copy", "paste" and so on.
I have tried creating a RichEditableText, and its contextMenu property actually contains a ContextMenu object. I am at lost as to why the RichEditableText object, which is stored in TextInput.textDisplay does not contain a ContextMenu object in its contextMenu property.
Can anyone shed some light on this and how I can ADD context menu items to the context menu of a TextInput?

Still couldn't work out why sparktext.textDisplay.contextMenu is NULL.
But here's what I did:
var testmenu:ContextMenu = new ContextMenu();
testmenu.hideBuiltInItems();
testmenu.clipboardMenu = true; //Use this to show the options such as copy, paste and so on.
sparktext.textDisplay.contextMenu = testmenu;

Related

Assigning actions to QMenu items

I have created a Qt project in which I'm using a widget and it does not support any menu in the designer's class, so it should be done programmatically. I succeeded in creating the menu and adding the items but I'm struggling in assigning any action for the menu items...
That's what I've done so far:
QMenuBar* menuBar = new QMenuBar();
QMenu *fileMenu = new QMenu("File");
menuBar->addMenu(fileMenu);
fileMenu->addAction("Save");
fileMenu->addAction("Exit");
QAction* newAct = new QAction(tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Exit"));
connect(newAct, &QAction::triggered, this, &MainWindow::on_action_triggered);
this->layout()->setMenuBar(menuBar);
But no action is triggered when I press The Exit item
addAction creates QAction and returns pointer to it, you dont need to create it explicitly, but when you do you must add item to menu with addAction, setting parent is not enough fileMenu->addAction(newAct);.

ComboBox selected value not getting translated

My app should have several languages. English is by default. Problem is that if user will switch to different language, everything will be translated except for ComboBox selected value. This is how it looks:
Code behind ComboBox is:
ObservableList<Currency> currencyItem= CurrencyDA.getCurrencies();
currenciesComboBox.setItems(currencyItem);
Callback<ListView<Currency>, ListCell<Currency>> currencyFactory = lv -> new ListCell<Currency>(){
#Override
protected void updateItem(Currency currency, boolean empty){
super.updateItem(currency, empty);
setText(empty ? "" : interfaceBundle.getString("currency_"+currency.getName()));
}
};
currenciesComboBox.setCellFactory(currencyFactory);
currenciesComboBox.setButtonCell(currencyFactory.call(null));
currenciesComboBox.getSelectionModel().selectFirst();
How can I get selected value refreshed?
From the doc
As the ComboBox internally renders content with a ListView, API exists in the ComboBox class to allow for a custom cell factory to be set. For more information on cell factories, refer to the Cell and ListCell classes. It is important to note that if a cell factory is set on a ComboBox, cells will only be used in the ListView that shows when the ComboBox is clicked. If you also want to customize the rendering of the 'button' area of the ComboBox, you can set a custom ListCell instance in the button cell property. One way of doing this is with the following code :
//(note the use of setButtonCell):
Callback<ListView<String>, ListCell<String>> cellFactory = ...;
ComboBox comboBox = new ComboBox();
comboBox.setItems(items);
comboBox.setButtonCell(cellFactory.call(null));
comboBox.setCellFactory(cellFactory);
So the only thing you have to add is :
currenciesComboBox.setButtonCell(currencyFactory.call(null));

Adobe Flex 3 List Control Selection and Change Event Problem

I created a list control at runtime as following:
var myList:List = new List();
ListArea.addChild(myList);
myList.percentHeight = myList.percentWidth = 100;
myList.itemRenderer = new ClassFactory (components.renderers.myRenderer);
myList.dataProvider = myDataArray;
myList.addEventListener(EVENT.CHANGE, historyBarClickHandler);
//Where myDataArray is an ArrayCollection consisting of my Custom ValueObjects.
When i execute the code it displays my list with custom item renderer, which is fine.
But when bring my mouse over it, it doesn't give any colour highlight which means it is not selecting.
Secondly, when i click on any of the list item, it doesn't dispatch any change event.
I tried a lot but couldn't understand it.
Please Guide
Thanks
Your itemRenderer may be causing another issue, but you're not listening for the correct event. It should be:
myList.addEventListener(ListEvent.CHANGE, historyBarClickHandler);

How can I add a user editable checkbox in QTableView using only QStandardItemModel

I have a QTableView and a QStandardItemModel. Is there have a column can contain checkboxes that are user editable without using delegates or using the abstract model classes? It is not that I can't do it, I just want to minimize the code, I would find it overkill for simple check boxes.
By using model.setData(index, Qt::Unchecked,Qt::CheckStateRole) this creates the checkbox but it is not user editable (text beside checkbox is).
I used modelTX.setData(index, FALSE) but this creates a combo box containing True and False.
I'll try setItemData.
pls, check if the following example would work for you:
QStandardItemModel* tableModel = new QStandardItemModel();
// create text item
tableModel->setItem(0, 0, new QStandardItem("text item"));
// create check box item
QStandardItem* item0 = new QStandardItem(true);
item0->setCheckable(true);
item0->setCheckState(Qt::Checked);
item0->setText("some text");
tableModel->setItem(0, 1, item0);
// set model
ui->tableView->setModel(tableModel);
hope this helps, regards

How to retrieve the pre edited value of the cell of a datagrid to an itemeditor in a flex

I wrote a custom item editor for a datagrid in flex. My question is how to retrieve the pre-edited value of the datagrid cell after the item editor initializes and also in the custom item editors code.
I don't think it is possible to get the old value once you are in the item editor. I would do this manually by listening to the "itemEditBeginning" event and keeping a variable with the value of the cell. You can then reference that value through the "parent", "parentDocument" or "outerDocument" properties in the item editor, depending on whether you are using an inline item editor or a separate class.
In the "itemEditEnd" event you can access the old value as:
var oldValue:String = event.currentTarget.dataProvider[event.rowIndex].VALUE_FIELD;
and the new value as:
var txtControl:mx.controls.TextInput = event.currentTarget.itemEditorInstance as mx.controls.TextInput;
var newValue:String = txtControl.text;
If you are using a custom itemRenderer you need to change "mx.controls.TextInput" for your custom itemRenderer.

Resources