PDA

View Full Version : Application's window not showing properly in a touchscreen



embeddedmz
30th July 2019, 19:57
Hello Qt Experts,

With a touchscreen (Chalkboard Electronics) and under Ubuntu (using Openbox as a window manager), I am unable to display properly my application's window (maximized upon showing):

13212

The application's window with a normal screen (and another OS) :

13213

Can someone tell me what's going wrong (dpi issue ?) and how can I fix this issue ?

Below, the output of xrandr :

Screen 0: minimum 8 x 8, current 1366 x 768, maximum 32767 x 32767
HDMI-0 connected primary 1366x768+0+0 (normal left inverted right x axis y axis) 220mm x 120mm
1366x768 60.00*+
1920x1080 60.00
1280x720 60.00 59.94 50.00
1024x768 60.01
800x600 60.32
720x576 50.00
640x480 59.94
DP-0 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)

Thank you very much.

d_stranz
30th July 2019, 21:58
The problem may not be a DPI problem as much as it is a problem with the choice of fonts and widget sizes used in your layout. First, it looks like you have chosen a font that is too large in the left-hand panel of your splitter. In addition, your labels are too long for one line - you should try to split them over two lines if possible. On the right-hand side, it looks like you have set a minimum width for the plot window that is too large. As a result, the tab widget can't shrink to fit everything onscreen. (If the plot widget was allowed to resize smaller, then the tab widget would likely look different - instead of the tabs being chopped off, there would be a handle to permit you to scroll right for more tabs. Therefore I conclude your plot widget's minimum size is too large).

Just guessing what's wrong from having seen similar problems in the past and tracing it back to bad choices made when laying out the UI.

embeddedmz
31st July 2019, 12:56
Hi d_stranz,

Thanks for your reply. In both screenshots, I am using the same font (I didn't change the font in the code, I kept the default one: Abyssinica SIL, size 10). I don't know why in the touchscreen it appears bigger than in normal screen version (DPI stuff ?) Otherwise, I have to be careful : I just can't reduce the buttons size for example, it could prevent a user from pressing (tapping) them (I implemented a virtual keyboad by the way...).

Is it possible to apply a default font (interested only on size) to all the app's QWidgets ?

I forgot to mention that I don't understand why in the left panel some elements are not showing completely ? (e.g. Range radio buttons and Save/Display checkboxes). I thought using layouts prevents this kind of problems ??!? and anyway, the window exceeds the dimensions of the screen, so why Qt is not letting these elements expand correctly ?

I made some changes, the geometry of the window, as seen from Qt Creator, is now 1218 x 697, but in the touchscreen the window is still exceeding though I'm below the touchscreen resolution.

I am not using a splitter, panel and plots are arranged in a grid layout (and their elements are arranged in vertical layouts).

Lesiok
31st July 2019, 13:18
Is it possible to apply a default font (interested only on size) to all the app's QWidgets ?



QApplication::setFont( new_font );
foreach(QWidget *widget, QApplication::allWidgets())
{
widget->setFont(new_font);
widget->update();
}

embeddedmz
31st July 2019, 16:32
I think I understood the problem (or excatly what d_stranz said) : sizes of checkboxes and radiobuttons are in pixels right ? so in small screen (for instance the touchscreen), they may not appear completely isn't it ?

With a ruler, I checked that the text labels have the same length in both screen, but not the buttons or the other graphical widgets.

I don't know if there's a technique to create a widget by defining its size not in pixels but in centimeters for example so it can be displayed the same whatever the screen used.

UPDATE: I really don't understand what's going on...

d_stranz
31st July 2019, 17:35
@Lesiok: If you set the QApplication font before creating any widgets (eg. in main()), then the loop to set the font in the app's widgets is not needed. Your loop code is needed if you want to change it on-the-fly after the GUI has been built. I would be curious to know if setting the font dynamically would also result in a re-layout of the UI and resizing of widgets where needed.

@embeddedmz: The QScreen class has methods that return many of the physical and logical properties of the display device. If you are able to debug the code on your embedded device, you might add some calls to retrieve the geometry() of various widgets, maybe in their showEvent(). The show event is called after the widget is fully laid out and sized, so it should contain the true pixel dimensions of the widget. It might give some clues as to why your widgets are being clipped.

Lesiok
31st July 2019, 19:08
@Lesiok: If you set the QApplication font before creating any widgets (eg. in main()), then the loop to set the font in the app's widgets is not needed. Your loop code is needed if you want to change it on-the-fly after the GUI has been built. I would be curious to know if setting the font dynamically would also result in a re-layout of the UI and resizing of widgets where needed.
Yes, I know. This is the code to change the font in a running application without restarting.

embeddedmz
31st July 2019, 23:47
I found the problem : the panel had a maximal width size set to 400 (instead of the usual big number), I lost one day or two because of that...

I can handle the rest of the small issues. Thanks everybody !

d_stranz
2nd August 2019, 01:01
Been there, done that. Eventually you learn that Qt is smarter than you are and leave the defaults alone :-)