How to enable WebGL content inside QtQuick2 / QtWebKit within a QML application? - qt

I'm doing some basic tests with a QML application to deliver WebGL content on desktop apps.
The basic test is the following code:
import QtQuick 2.0
import QtWebKit 3.0;
Rectangle {
width: 800
height: 600
WebView {
url: "http://learningwebgl.com/lessons/lesson03/index.html";
anchors.fill: parent
}
}
The window is shown and the HTML content appears but no WebGL content is shown.
I've tested it with other pages (like threejs examples). It seems that 3D content is somehow processed (at least I suppose it from my fan!), typical framerate display is shown (40 to 60 fps in many cases), but visually I can't see the WebGL content.
Do I miss something? Should I enable something else to support WebGL rendering inside the WebView?
I'm using Qt 5.4 on Windows 8 with VS Express 2013

Related

QML application style

I'm writing an application for tablet using QML.
The main QML file of the application is something like this:
ApplicationWindow {
id: mainWindow
visible: true
title: "MyApp"
menuBar: MenuBar {
Menu {
title: qsTr("File")
MenuItem {
text: qsTr("Open project")
}
MenuItem {
text: qsTr("Exit")
onTriggered: Qt.quit();
}
}
}
}
If I run the app on an Android device, the menu is styled like a standard Android menu, that is a button (with the "3 points" icon) on the top right corner. This is very good.
Instead if I run the app on a Windows device, the menu is like a standard desktop application menu (the traditional file menu...). This style is not suitable for a tablet application.
There is a way to choose the style of the application?
Thanks!
The correct style should be picked up by default. If it's not, it means that a style for that device type (e.g. touch) isn't available. If you want to use a specific style, you can set the QT_QUICK_CONTROLS_STYLE environment variable before running your application. However, some styles can only be run on the platform they are built for. For example, the Android style needs a specific file from a directory on the device in order to function properly.
Note that Qt Quick Controls have a stronger focus on desktop. If you have the opportunity, and you do not need a native style, I'd recommend trying out Qt Labs Controls. They are more touch-oriented, and have a style that implements Microsoft's Universal Design Guidelines.
They currently have three different styles available, and any style can be used on any platform.
Without styling, components from Qt Quick Controls are supposed have a native look. You can make your own styles for almost all of them, though.

Fuzzy text in Qt application?

I wrote a Qt application that drawing text, when using a certain font (Inconsolata) in small point sizes, it looked fuzzy:
But when using other font (Courier New, etc..) it's just fine:
What strange here is that other applications using that font looks normal, here is a contrast (left is vim, right is my application):
What would be the problem here?
Environment:
Window 7 Ultimate 64-bit
PySide 1.2.2 & Qt 4.8
Inconsolata.otf (http://www.levien.com/type/myfonts/inconsolata.html)
Code example (the problem is more serious on a dark scheme):
from PySide.QtGui import *
app = QApplication([])
label = QLabel('hello\nworld')
label.setStyleSheet('QLabel {background: #000; color: #fff;}')
label.setFont(QFont('Inconsolata', 11))
label.show()
app.exec_()
You can try changing the Qt font style strategy of your QFont and see what gives the best result.
For example to enable antialiasing on your application's default font, you can do:
QFont font = QApplication::font();
font.setStyleStrategy(QFont::PreferAntialias);
QApplication::setFont(font);

Intel xdk, the scrolling option not working on real device

when I am running my apps on emulator or virtual device, its working fine, but when i am running it on real device the screen not scrolling, I am using an Intel xdk bootstrap design. Please can someone tell me how I can solve this issue.
The issue that you are experiencing is present in Android devices with versions below 3.0 due to the interpretation of css properties by the WebView. This is an issue related to the styling created by the Intel XDK App Designer within the index_main.less.css file. This file is auto-generated and stored within the css folder in your project directory every time you make changes to layout with the Designer.
In order to resolve this issue, you will need to make changes to the following css class.
*index_main.less.css*
.......
/*.upage {*/ /*Comment out this line*/
.upage-outer { /*Add this line*/
overflow-x: hidden;
}
.......
You should now be able to scroll your app.
Note: The index_main.less.css file will be re-written every time UI changes are made to the layout.

Bitmap fonts in Qt Quick QML

I've a png bitmap with many "glyphs" drawn one after another and a text file that relates an ascii number with a position and size in this bitmap. The glyphs are hand-drawn using different colors and transparency levels.
Somehow I need to open and use this font on QML. Unfortunately, it seems QML does not support bitmapped fonts "as is".
Is there any solution?
I've worked on the solution some days after posting this question. Since then, it seems there are lots of people still trying to use "old-school" bitmap fonts in Qt Quick. The solution I found is really elegant and has extremely good performance.
import QtQuick 1.1
Row {
property string text: ""
Repeater {
model: text.length
Image {
source: "bitmapfont/" + text.charCodeAt(index) + ".png"
}
}
}
Save as “TextBitmap.qml” in the same directory with your other qml code and then create a sub-directory called as the font name (“bitmapfont” in this example). You’ll need to draw or cut each bitmap font glyph individually and store them in that subfolder as a separate .png whose name is the Unicode of that glyph; for example bitmapfont/65.png for character ‘A’, bitmapfont/66.png for character ‘B’ and so on.
When this custom TextBitmap element is rendered for the first time –or anytime the text property is changed– Repeater will automatically create an image element for each character in text, each displaying the corresponding .png from “bitmapfont”.
Use it like this:
import QtQuick 1.1
Rectangle {
width: 800
height: 500
TextBitmap {
text: "Hello Bitmap Fonts!"
}
}
In http://www.royconejo.com/bitmap-fonts-in-qt-quick-qml/ you will find a more elaborated TextBitmap element, a video of how it looks and even a sample project.
I hope it helps someone!
This is not directly possible using Qt's font infrastructure: there is no support for bitmapped fonts. You can use QFontDatabase::addApplicationFronFromData, but then your font must be available as a TrueType font or a TrueType font collection.
The workarounds would be to.
Render the "text" using such a font into a QImage and show that using QML. This is OK if the text is static and doesn't change often.
Render the "text" using QQuickPaintedItem.

High-res iPad icon in Flex/Flash Builder 4.6

Apple says that a 144x144 application icon is now required for the high-res iPad. But adding an <image144x144> element to the application descriptor file in Flex 4.6 gives an error 103: application.icon.image144x144 is an unexpected element/attribute.
Is there a workaround for this? Perhaps through the iPhone InfoAdditions area of the application descriptor?
Are you adding <image144x144> under the <icon> tag in the xxx-app.xml file? It works OK for me. I have had problems with icons with transparent pixels but, normally, uncommenting the <icon> section works fine.
For anyone coming across this question, this thread suggests that Adobe needs to release an update to support the larger icon size, and that the user Colin Holgate will post if he hears news about it from Adobe.

Resources