Custom popup in JavaFX - javafx

Is there any way to create a custom PopUp in JavaFX? I can't use tooltip, since I would like it to appear on double click, also I would like a different style than the standard tooltip.
My demands for the popup are:
1. If the user double click, show the popup
2. if the user clicks outside the popup, hide it

See this guide on all the different types of popups.

Use Popup.
Popup popup = new Popup();
// add content (you can add as many nodes as you want)
popup.getContent().add(new Label("Hello Popup!"));
// show (move this to the double-click listener)
popup.show(primaryStage);
// hide (move this to the click listener)
popup.hide();

Related

How to use CustomButton to change QWizard page in Qt?

I have a QWizard with 2 custom buttons (on top of the Back\Next buttons).
I wish that a click on my custom button will change to another QWizardPage.
How do I do that?
Thanks
That would be doable by connecting the custom buttons clicked signal with a slot which handles moving to next page.
QWizard wizard;
wizard.setButtonText(QWizard::CustomButton1, "Custom button");
wizard.setOption(QWizard::HaveCustomButton1, true);
QObject::connect(&wizard, &QWizard::customButtonClicked, [&]
{
wizard.next();
});
The code above would create a wizard with a custom button which would function like the default "next" button. If you want to create a dynamic (as opposed to linear wizard which it is by default) you would need to reimplement QWizard::nextId(). Please see:
https://doc.qt.io/qt-5/qwizard.html#nextId

How to make pop-up data reflect selected record?

The case:
I have Activities as datamodel.
I have set Activities to have many-to-many relationship with themselves to represent a Parent / Child relationship.
I have set up an accordion widget. Each row of the accordion contain basic data about the Activity record + some buttons.
I have set one of the button's onClick functions to open a popup, which allows me to edit the Activity detail in a form.
When I click a different record from the same accordion, the form from the popup reflects the data in the selected record.
The problem:
I have nested accordions which represent the "Child" Activities of the Parent Activity.
I have also added a similar button, which opens a popup. I can open the popup, which targets the child records, but cannot make it open the specific record, from which I pressed the button.
So the popup open by default on the first child.
Please help - how can I make the popup change naturally to reflect the datasource / selected record of even nested datasources?
What I tried:
In order to try and make to popup work I have tried to set the datasource based on the relationship:
Activities: Sub_Activities(relation)
This works to the extent of showing the related items, but popup content does not dynamically change on clicking a different child record or clicking the button from a different child record.
In both cases what is shown is the first child record.
What I understand is that you have a set up in which you click a button and a popup shows. The popup should let you view/edit the record referenced in the row where the button is. If that is the case, then probably you already have almost everything setup for the next thing to work. First, add a string custom property to the popup and name it selectedKey. Then, on the onClick event of the button that opens the popup, add something like this:
var key = widget.datasource.item._key;
app.popups.MYPOPUP.properties.selectedKey = key;
app.popups.MYPOPUP.visible = true;
Now, go to the popup content and add the following on the onAttach event handler:
var key = widget.root.properties.selectedKey;
widget.datasource.selectKey(key);
This is the general idea of how to make it work; However, in order for it to work, your datsources in the widgets should be properly set up. Good luck!

JavaFX DatePicker hide on mouseExited

How do i set this kind of behaviour?, currently the hover(mouseEntered) is fine, it shows up the DateChooser whenever the cursor goes inside the DatePicker, but whenever the mouse exits from the DatePicker it hides the DateChooser. I can´t find such method that gives access to the DateChooser itself.
It´s only fixed to not close the DateChooser when the cursor goes under the DatePicker, but the DateChooser should be close whenever the mouse goes out from it.
datePicker.setOnMouseEntered((event)->{datePicker.requestFocus();datePicker.show();});
datePicker.setOnMouseExited((event)->{if(event.getY()<23)datePicker.hide();});
Accessing the skin allows you to access the content of the popup which allows you access to the popup's Scene, which allows you to add a onMouseExited handler to that scene for hiding the popup:
EventHandler<MouseEvent> exitHandler = e -> datePicker.hide();
datePicker.setOnShown(evt -> {
DatePickerSkin skin = (DatePickerSkin) datePicker.getSkin();
Scene sc = skin.getPopupContent().getScene();
sc.setOnMouseExited(exitHandler);
});
Not a nice solution, since it requires accessing the skin located in the com.sun packages, but it is a solution.

How to identify the viewcontroller is clicked from More Tab or Separate tab in UITabBarController?

I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation bar back button in to my custom segment control with different purpose. This navigation controller is placed one of the separate tab in the uitabbarcontroller. If this is used as the separate tab bar then no problem.
But if i use this navigationcontroller inside the more option in tabbarcontroller i am not able to come back to the more option list because of backbutton is overridden in my navigationcontroller.
My idea is add one back button only if my navigationcontroller is used more option tab otherwise i need to hidden the back button.
Please help me in this issue?
You can check if a view controller is in the 'more' section as follows:
BOOL isOnMoreNavigationController = [tabBarController.moreNavigationController.viewControllers containsObject:myViewController.navigationController];
From a UI consistency perspective it might be better to always show the back button in its standard position and move your custom buttons to some other place.

Show/hide QDockWidget?

I have a dock widget, now I want to add a "Window" menu to show/hide the widget. Easy enough to do with
showPropWinAct = new QAction(tr("&Properties"), this);
showPropWinAct->setStatusTip(tr("Show properties window"));
showPropWinAct->setCheckable(true);
connect(showPropWinAct, SIGNAL(toggled(bool)), propertiesWindow, SLOT(setVisible(bool)));
The problem is when the user clicks the [x] on the widget, the showPropWinAct doesn't get toggled. How can I listen for this event, and toggle the action properly, without firing off a 2nd setVisible signal (one from the close event presumably, and one from the connect above)?
Instead of creating a new action, simply get the action from the QDockWidget itself and use that. It'll take care of state for you:
http://qt-project.org/doc/qt-4.8/qdockwidget.html#toggleViewAction
QAction * QDockWidget::toggleViewAction () const
"Returns a checkable action that can be used to show or close this dock widget.
The action's text is set to the dock widget's window title.
"

Resources