Qt Virtual Keyboard: Set Custom Font Size - qt

I have created a custom keyboard layout for my QtQuick application using the VirtualKeyboard in 5.9.2. I am trying to fit this keyboard on a small screen to make it more readable and usable than the Virtual Keyboard was stock.
There are two things I need to do which I cannot seem to make work:
Make the font larger on the keyboard buttons. After changing the layout, the buttons are larger, but the text on the buttons is still the same, tiny size. It looks strange.
Reduce margins surrounding the keyboard to use up more of the available screen space. The keyboard is already set to the width of the screen. I could make it larger, but if I could simply reduce the margins that would be a much more simple solution.
Any help would be appreciated!

you can use screen properties in qml and set font.pixelSize and margin according to screen height and width.
import QtQuick.Window 2.2
and use below properties
Screen.pixelDensity
Screen.height
Screen.width

The best way to solve this is by using a style.qml sheet. This is answered in a different question of mine located here: Qt Virtual Keyboard Custom Style

Related

How to resize width of scrollbar in WebEngineView?

I am using QML component WebEngineView, It has been observed that, scrollbar is by default implemented in WebEngineView, but there is no interface to change the width of scrollbar. This is required in my use case where I cannot use swipe, I can use only mouse drag operation on scrollbar of the WebEngineView in order to view all hidden part of the web content where length is outside the view port area. Since Scrollbar size of WebEngineView( default is very small 15pix )its quite difficult to drag exactly on the area and drag using mouse.
Can Some one suggest how to customize the scrollbar of WebEngineView?
or
I can find webengine source code, then modify and build for the purpose?
or
Any Style Can apply on WebEngineView ?
I am using Qt 5.6.2
Qt Webengine Source code Observation:
QML Webengineview is not set any scrollbar width internally, instead it uses back-end scrollbar probably of chrome’s.
WebEngineView uses the scrollbar that comes from the Chromium backend and there is no QML or C++ API to customize it directly. However WebEngine supports to change these scrollbar styles in CSS, so the only thing you can do is to install a user script which applies a bigger width on all -webkit-scrollbar.
See this related example: http://doc.qt.io/qt-5.10/qtwebengine-webenginewidgets-stylesheetbrowser-example.html
And your stylesheet could look like this:
::-webkit-scrollbar {
width: 40px;
}

In creator it's huge, but window is small

I have this problem. As you see in creator it is all huge but in window application it is normal, because in designer I had to make it big, so application look better. Why is it like this?
You need to set the minimum size of the buttons bigger in order to have them show bigger. The sizePolicy is also your friend when working with UI elements in Qt. By default this property is set as preffered which is usually a very good setting, but does not set things bigger than they must be.
Also, consider using layouts for more dynamic control over the UI.

How to change logical DPI for QML app?

I want to control the pointSize-to-pixel scaling of all Text elements in my Qt 5.2.1 QML/C++ app.
I have a QML singleton component with target display properties like width, height and dot pitch that calculates appropriate pixel sizes for common dimensions such as the recommended size in pixels for a touchscreen button. This works fine for controls I write, but the Text element has a perfectly good font.pointSize that I would like to use if I could just set the logical DPI used for text scaling.
I use this to simulate target devices with very different screen DPI while debugging on my 96 DPI development screen. For example, I would like to run my app that targets a 1280x720 133DPI display and has an element like:
Text { font.pointSize: 72; text: “Xy” }
display 133 pixels tall, not the 96 pixel tall text I get because the OS tells Qt that I have a 96 DPI monitor attached. I want to override the logical DPI scaling for my application.
I can see the logicalDotsPerInchX through the QGuiApplication QScreen list. There is tons of documentation on how to get the logical DPI. But I cannot find any information on how to change it.
How can I change the logical DPI for my Qt app?
I don't think you can simply change the DPI values in the QScreen class (there are only public getter methods).
Maybe there are some "hacks" for that problem if you modify the QScreen class and add a public setter or something yourself and then recompile Qt, but that might be some work and takes a lot of time...
Another solution might be to just add a scale factor to your font sizes? I don't know how many you have but that can be simply done in QML and I use something like that even for production setting to scale the fonts and other sizes properly to the device.
You could use Screen.pixelDensityor just define your custom QML property and multiply that to all font sizes? if you do that you can dynamically change the sizes while the app is running.

Fixing sizes of widgets in QT designer layouts

I have a QT form that has literally hundreds of widgets and to make them all fit on the screen at once (as required) I need to make them pretty small. The Form will have fixed (non resizable) size when used. I can resize the widgets to the desired height/width and use the appropriate (small) font size, make their size policy "fixed" etc. However, as soon as I start putting them into layouts, they gow to some, much larger minimum size. This is particularly true for the height of the widgets, but width is sometimes affectged as well.
My problem would be solved if I knew how to do one of the three following things:
Change a layout's default minimum size(s) for widgets.
Force a layout not to alter widgets sizes.
Use Qt designer to nicely align widgets in grid-like formats without using layouts.
I searched extensively Qt designer's docs and SO, to no avail.
Help is greatly appreciated
Use layouts with QWidget::setFixedSize in code (or alternative you can set the fixed size policy for each widget in designer) or you can use QLayout::setSizeConstraint

Resolution handling in QMainWindow

I've a QMainWwindow, and I've fixed its size.
i.e. I've set Minimum and maximum size of the window to the same number.
Could anyone tell me whether this will be a problem if I'm to use this in another screen with a different resolution, and if so, how am I to handle it?
Kindly advise, and also if there's another way ( perhaps more elegant) to set the size of the QMainWindow.
UPDATE :
I have a QMainWindow with a QTableView as a widget, amongst others. When I expand the main Window, the tableview does not, and it leaves an ungainly blank space, so I fixed the size.
If I were to make it resizeable, how do I expand the QTableView widget, alongwith the QMainWindow. I have a Central Widget, this widget has a vertical box layout, and to this layout I've added the 3 widgets, one with QGridlayout, one horizontal line, and the other QTableView. The QTableView, on its own, is not inside a layout.
I'd imagined this would be sufficient to expand the table too, once QMainWindow were expanded, or reduced, but it doesn't happen.
How do i go about it, i.e., expanding the QTableView as well?
Thanks.
It will be a problem if you fix the size to one that is larger than the screen can handle. There are various ways to scale the size of a window according to the screen size. I recommend using QApplication::desktop(), which will return the desktop widget (you may need to #include <QDesktopWidget>. Note that this widget can actually encompass multiple screens, so if you just want the current screen, you can just do:
QRect screenGeometry = QApplication::desktop()->screenGeometry();
You could alternatively use QDesktopWidget::availableGeometry().
It is worth mentioning that among Qt users, I think there is a general dislike of fixed size windows. Most recommend taking full advantage of the Qt layout system, which provides lots of flexibility for resizing windows. I'm not saying you should definitely do this, because all projects are different, but it could be worth looking into.

Resources