How to disable rendering in QML WebView? - qt

I am currently building an application that makes use of QML WebView (import QtWebKit 3.0). The users need to resize the WebView very often (I am using a QML SplitView), however this leads to the UI to lag extremely whenever the app window is resized. Is there any way to prevent this?

Instead of changing the width and height properties change scale property of the WebView.
At beginning of the resize save initial values of width and height.
On resize don't change width and height. Instead set scale to newWidth divided by width at beginning of the resize.
When resize ends set new values of width and height to these properties and set scale to 1.
EDIT:
Since you don't have control of width and height properties you can replace WebView with Rectangle with color set to "transparent". Then you can place WebView on Rectangle and watch how width and height of Rectangle are changing.
Now two things.
If you don't know when resize starts and when ends use Timer with interval for example 100ms. Restart Timer and update scale every time width and height of Rectangle changes. When Timer is triggered set real width and height.
If ratio of width and height of Rectangle is not constant use QML object Scale. With it you can change xScale and yScale independently.

Related

Responsive CheckBox JAVAFX

This is my first javaFX project. The project I'm working on includes a feature where the application window can be resized. Upon resizing the window, I expect all objects in my window to increase proportionally according to the window resize. I am not getting this to work with the "CheckBox" Objects.
As you can see below highlighted in red, a CheckBox object is shown before and after a window resize. Before the resize the red checkbox nicely fits in the green box, but after the resize, the red checkbox is the correct (scaled) width, but did not increase in height as I'd expect. Where should I begin my effort to make my CheckBox objects more vertically responsive?
Minimized
Maximized
As you can see (IN RED), the CheckBox scales horizontally as I expect, but it doesn't scale vertically to occupy the remaining space!
After a lot more research and helpful responses, I gathered a solution that works.
A "DoubleProperty" object is made, and binded to the width of the container holding my checkboxes. Call this container, "dryLeafGridPane" for example.
DoubleProperty checkboxFontSize = new SimpleDoubleProperty(10);
checkboxFontSize.bind((dryLeafGridPane.widthProperty().divide(36)));
The .divide(36) scales the CheckBox's font size to 1/36 the gridpane's width.
Finally, I just add the new font size using CSS.
dryLeafGridPane.styleProperty().bind(Bindings.concat("-fx-font-size: ", checkboxFontSize.asString()));
Here is a gif of the (slightly more) responsive app!
You can choose to increase the font size on the root pane when you go full screen. For example:
rootPane.setStyle("-fx-font-size: 150%;");
That isn't perfect though... it seems the size of the box that is checked doesn't scale with the font.

JavaFX sizes doubts

If I have a window with a BorderPane and its size properties are:
Min Width: USE_PREF_SIZE.
Min Height: USE_PREF_SIZE.
Pref Width: 600.
Pref Height: 400.
Max Width: USE_PREF_SIZE.
Max Height: USE_PREF_SIZE.
Why can I resize the window? I haven't clear how works these properties (I read the API and I still don't understand).
The min/max/pref width and height of a Region are used by a parent layout pane to determine how to size and position the child nodes of that pane. So if you put your border pane in a parent which manages layout (i.e. a subclass of Pane), then those settings would be adhered to, if possible.
However, a Scene is not a layout pane and basically performs no layout. It has one root node (a Parent instance), and simply sizes the root to the size of the Scene. In turn, the scene is sized by the window and takes on the size of the window minus any space needed for a window border and decorations.
Consequently, these settings on your BorderPane have no effect on the resizability of the window. To turn off the ability to resize the window, use the window method setResizable(false). Similarly, if you want to impose minimum or maximum sizes on the window, use the window's min/max width/height properties.

JavaFX 2 Not Resizing UI Control Based On Window Size

I'm new to JavaFX and I want to learn. I have a Group containing a GridPane that contains a lineChart, TableView and HBox (status bar) but I'm experiencing the following problem:
I am using screen resolution 800 x 600 on Windows XP when I change the screen resolution to 1024 x 768, the lineChart, TableView and HBox does not expand to fill the new window size, it leaves a large space at the right. How can I make controls fill the width of the window when window is resized.
The TableView's height extends beyond the boundary of the window, the bottom border of the tableView and the status bar is not showing. How can I make sure that the tableView does not extend beyond the window height?
How can I make controls fill the width of the window when window is resized.
Instead of using a Group as the root of your Scene, just make the GridPane the root of your scene.
The layout Pane classes automatically expand and shrink to fit their available area as the area changes whereas a Group does not.
How can I make sure that the tableView does not extend beyond the window height?
Your scene will probably end up being completely enclosed in the window if you just make the change above and use a layout pane as the scene root.
Additionally, if the sum of the minimum sizes of the window elements is greater than the window size, then the TableView will extend beyond the boundaries of the window, in which case you can either reduce the minimum sizes of elements (by using smaller fonts or less text, explicitly setting minWidth/minHeight values etc.) or wrap elements in a ScrollPane - but in your case those modifications are probably unnecessary.
you should use userComputed size (height,and width) property.

Widgets next to each other same size in Qt

I have two widgets, one arbitrary (usually a QLineEdit), and one QLabel which displays a Pixmap. They are placed next to each other with a QHBoxLayout. The widget with this layout is in turn placed in another layout.
Now, what I want is that the label with the pixmap is automatically resized so that it is as high as the arbitrary widget next to it. However, even when I set the label's sizePolicy to Maximum, it still seems to expand to the original pixmap size, instead of resizing the pixmap and shrinking to match the other widget. Instead of having two equally large widgets I have the arbitrary one which is smaller than the pixmap next to it.
Any ideas how to get the size of the pixmap label to match the size of the widget next to it?
How about:
int height = arbitraryWidget->height(); // get desired height.
label->setSizeHint(QSize(label->width(), height); // set size hint to current width and desired height.
label->setSizePolicy(QSizePolicy::Fixed); // optional, but this ensures size is desired.

how do I find the height of the children in a TabNavigator, without the height of the Tabs?

I'm having sizing issues with a TabNavigator. The direct children of the TabNavigator are Canvases, and within these I am adding Images. I'm trying to resize the images to fit within the Canvas without scrollbars. The Canvas height is set to 100% of the parent, which is the TabNav. Then I'm setting the image.height = parent.height * .9
The result is that Flex is generating scrollbars because the images are too high. It appears that the root cause is that the height property of the TabNavigator is the height of the entire component, including the height of the tabs. I'm assuming therefore it also contains that little strip of space between the tabs and the children of the TabNavigator.
This makes sense, but is there a property that returns only the height of the children?
I'm aware of the scrollbar policy properties and I've experimented with those. I know I can also try a different multiplier for the image size to get it to fit. It just seems like there should be a property to get the size of the space for the children.
Looking through the source, there's a "contentHeight" property that seems to be the thing you want.
The method ends with this line:
return unscaledHeight - tabBarHeight - vmTop - vmBottom;
which seems to be exactly what you're looking for. Unfortunately this property is protected, as is the case with many things we developers want out of the Flex library. :)
Your quickest solution using this would be to sub-class TabNavigator and expose this property publically; or you could just do this calculation yourself:
image.height = (parent.height - TabNavigator(parent).tabBar.height) * .9);

Resources