When I try to put a combo box inside another combo box, the inner combo box can be selected fine however I cannot use the inner combo box when it is selected. Is there a way to make the inner combo box functional?
Example code:
ComboBox outerBox = new ComboBox();
ComboBox innerBox = new ComboBox();
innerBox.getItems().addAll("item1", "item2", "item3");
outerBox.getItems().add(innerBox);
As I said the inner box can be selected but it cannot be used.
Related
Is there any way I can have an event that only triggers if I click the Title of a TitledPane?
I have several Nodes in a Graph Editor and currently they are draggable.
But I want them only to drag when i drag the Title not if I click anywhere on the pane.
the mouseClick event seems not to work for me.
Does anyone have suggestions?
Don't set the text on the titled pane, but instead create a label and set it as the graphic for the titled pane. Then you can register a mouse handler with the label:
private TitledPane createClickableTitledPane(String text) {
Label label = new Label(text);
label.setOnMouseClicked(e -> System.out.println("Click on "+text));
TitledPane titledPane = new TitledPane();
titledPane.setGraphic(label);
return titledPane ;
}
StackPane titleRegion = (StackPane) titledPane.lookup(".title");
titleRegion.setOnMouseClicked(System.out::println);
EDIT:
Sometimes titledPane.lookup(".title") returns null which means CSS is not applied to the node. To resolve this issue, you need to use applyCss() and layout() on the pane that contains the TitledPane.
See:
JavaFX TitledPane lookup(.title) returns null
I need to use QTableWidget with checkboxes instead of text in items. Checkbox must be in the center of item.
Examples which I tried work while checkbox is checked. If I uncheck checkbox it disapeares.
You can set the checkbox to be centered with this code:
QWidget *pWidget = new QWidget();
QCheckBox *pCheckBox = new QCheckBox();
QHBoxLayout *pLayout = new QHBoxLayout(pWidget);
pLayout->addWidget(pCheckBox);
pLayout->setAlignment(Qt::AlignCenter);
pLayout->setContentsMargins(0,0,0,0);
pWidget->setLayout(pLayout);
pMyTableWidget->setCellWidget(0,0,pWidget);
(I don't know if I understood you well here) And if you want to make your checkbox disappear when you uncheck it, you need to connect clicked signal of checkbox to a slot, that will make your checkbox invisible. Use connect method like this:
connect(checkbox,SIGNAL(clicked()),this,SLOT(checkboxClicked()));
You need to create slot checkboxClicked where you will be checking if the checkbox is checked or not. If not then you have to set it invisible. Example:
QCheckBox* Chb = qobject_cast<QCheckBox *>(QObject::sender());
if(!Chb->checked())
Chb->setVisible(false);
I want to auto select the first element in a combo box:
final ComboBox selectStatus = new ComboBox();
selectStatus.getItems().addAll(
"Active",
"Blocked",
"Suspended"
);
selectStatus.getSelectionModel().select(0);
selectStatus.setEditable(true);
But when I add editable=true the combo box is empty. Can I solve this problem somehow?
Do like this:
//first set it editable
selectStatus.setEditable(true);
//then, set the value of the first item
selectStatus.getSelectionModel().select(0);
When you set it editable the values displayed is cleared, so you have to set the value after set it editable.
See the javadocs.
Can we place/keep dropdownlist item at particular position. Say for example I want to bind dropdownlist to datasource and then add new item which is placed at particular position in dropdownlist. How can this be possible.
You can use Insert method.
dropDownList.Items.Insert(index, new ListItem("Default Panel", "0"));
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