JavaFX Text preventing bottom layer from triggering mouse event - javafx

I have a PieChart with Text displaying their values. My pie chart has a mouse event listener such that when i mouse over the chart, it creates a glow effect.
The problem here is that when my mouse goes over the Text, it blocked my mouse listener as my mouse is effectively over the Text instead of the PieChart. Is there any way i can display the Text but make it such that it's "invisible" to my mouse?
Pseudocode:
PieChart chart = new PieChart();
chart.setData(MY CHART DATA);
chart.getData().forEach(d -> {
Text text = new Text();
text.setText((int)d.getPieValue()+"");
MOVE TEXT TO THE RESPECTIVE PIE AREA
}

Thanks #fabian
"text.setMouseTransparent(true);" did the trick!

Related

TableView Scrolling on Button Click Qml

Is there any property by which i can scroll up and down on button clicked in tableview. I don't want vertical scroll bar visible but i want to make it scroll on button clicks ?
I don't want to increment currentrow value, i want to make currentrow value fix,
I just want to scroll tableview list on button click.
You can use flick method to scroll TableView. For scrolling down:
myTableView.flick(0, -1000)
and for scrolling up:
myTableView.flick(0, 1000)
Here 1000 is the velocity in y direction. You can change it to your desired value.

Edit : How to zoom in and zoom out Content in Hbox draggable node in javafx

Situation :
i have HBox with Labels and while click on it should be look like zoom in and zoom out.
Consider following String of Labels
ATATATATATATATATA.....50 char
when i zoom it shows me 25 char with some zoomable view how i can get result.
If you hold String of labels inside HBOx then Simply on Every click you increase width of label
create map with labels width and click
on each click maintain flag and set width to label .
label.setWidth(value);
revalidate container.
That It. hope it will work

SceneBuilder Tooltip over Label JavaFX

If I have a label with a text that's too long and I want a tooltip that shows the entire label text when I hover over the label with my mouse. Is that possible to do in SceneBuilder or do I have to do it programically for all my labels?
Under "Miscellaneous" in the Library pane (left side), you will find a "Tooltip". Just drag it and drop it onto the label in the Hierarchy pane below. Then you can select the tooltip and configure the text, etc.

How to increase the clickable area of a QPushButton in Qt?

The Back button in the top left corner of my touch user interface is a little hard to press on a resistive touchscreen, because the touch events are not so precise at the borders of the screen.
The visual size of the button can't really be increased because the screen space is needed for other things. Thus I would like to increase only the clickable area of the button. So when the user touches somewhere in the top left corner of the screen (as marked in red), the back button should be pressed. Note that the red area also overlaps another button. Ideally, the visual button state would also change to the "pressed" state.
Can anyone give me some pointers in the right direction? I have considered the following things, but I'm unsure which would work.
Overlaying the actual button with a larger, invisible button, painted with a transparent brush. But I have no idea how I could paint the smaller button as "pressed" when the user is pressing the invisible button.
Creating a new class based on QWidget, which has the size of the red area (with invisible background) and contains the actual button. Then relay touch events to the button so that it is pressed when the user touches the empty area.
Subclassing QPushButton and reimplementing QAbstractButton::hitButton to accept points outside of the button's area. But I guess that function would probably isn't even called when I touch outside the widget area.
To occupy more vertical space inside a layout, set buttons vertical policy to expanding.
To increase the clickable area without increasing the visual size, increase the margin.
To have the back button overlapping other buttons, don't put it to a layout. Instead set its parent directly and move it to the corner.
backButton = new QPushButton("< Back", mainWindow);
backButton->setStyleSheet("margin: 30;");
backButton->show();
backButton->resize(150, 90);
backButton->move(-30, -30);

displaying a text using QLabel ontop of another QLabel showing image has become such a pain

Its simple thing, but I can't figure out why the overlay text is not displayed ontop of another QLabel,
here is the code I have that sets the overlay label that has text onto another existing label displaying image
def _buildUi(self):
self.label = QtGui.QLabel()
self.overlayExifText = QtGui.QLabel(self.label)
self.overlayExifText.setSizePolicy(QtGui.QSizePolicy.Ignored,
QtGui.QSizePolicy.Ignored)
self.overlayExifText.setStyleSheet("QLabel { color : blue; }")
self.overlayExifText.setAlignment(QtCore.Qt.AlignTop)
self.label.setBackgroundRole(QtGui.QPalette.Base)
self.label.setSizePolicy(QtGui.QSizePolicy.Ignored,
QtGui.QSizePolicy.Ignored)
self.label.setAlignment(QtCore.Qt.AlignCenter)
self.setCentralWidget(self.label)
here is the method that updates the text for current image
def showImageByPath(self, path):
if path:
self.overlayExifText.setText("\n".join(list(utils.getExifData((path)))))
image = QtGui.QImage(path)
pp = QtGui.QPixmap.fromImage(image)
self.label.setPixmap(pp.scaled(
self.label.size(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation))
only first letter of the text gets visible. also I tried setting some default text then it displays text with black background then that area also shows the little bit more of data the is yielded by the second method above. For full code have a look at this repo
To display image and text simultaneously following approach can be useful:
Set the image as background image on label:
label.setStyleSheet("background-image: url(:/1.png);")
Set the text you want to display on top of the image:
label.setText("text")
..

Resources