Posts

Showing posts with the label Snippet

QML: CheckBox and RadioButton with description field

Image
Restarting from this post explaining how to add the word wrap feature to the CheckBox and RadioButton controls here will propose to add a description field under the main control text. This will be useful to give a short explanation concerning the use of the control itself.

QML: CheckBox and RadioButton with word wrap feature

Image
Standard QML CheckBox and RadioButton controls can be used in a very easy way but, at least until the current date, it have the problem if the text go over the parent control container is not automatically moved to the next line but is simply cutted out. This missing feature is called word wrap .

Linux: Translate virtual to physical addresses in user space

Image
Each memory allocated in a process use a special address system called virtual address. This is a special address used inside the process space. However, sometime, could be necessary to know the real physical address in system memory for different purposes in user space. Here a short snippet showing how to do.

QML: Change Android screen orientation programmatically

Image
In case your Android app require to dynamically set screen orientation for some particular interface is possible to directly call the system API allowing to choose one of the two standard orientations LANDSCAPE or PORTRAIT.

Access PCI device registry from Linux user space

Image
In case you need to modify registry of some PCI devices from Linux user space you can easily do by access to the /proc/bus/pci path where all PCI devices found on the system are listed.

Store and retrieve Android contacts photo

Image
Android default contacts are, basically, a database for store and retrieve phone contacts info. Here a short snippets showing a way to store and retrieve the photo of the contacts. Android contacts store photo in two format, large and thumbnail with two different way for retrieve it.

QML Snippet: Flickable TextArea and Material style problem

Image
Make a TextArea control flickable is a very easy task using new version 2 of QtQuick controls. However when Material style was applied it show a line on bottom side of control that, in case of full window edit control, is not so good to view.

Qt Snippet: Render SVG to QPixmap for high DPI screen

Image
Convert a SVG image to QPixmap format is a very easy operation using the Qt classes. Common examples that is possible to find into documentation, however, refer to a situation where the screen device have standard pixel ratio of 1.

Qt Snippet: QGraphicsView fitInView() and the unwanted margins bug

Image
In case you are working with Qt Graphics View Framework you probably make use of the QGraphicsView method fitInView() . This function, based to the official documentation, scales the view matrix and scrolls the scroll bars to ensure that the scene rectangle rect fits inside the viewport. 

Qt Snippet: Rounded corners QPushButton inside QGraphicsScene

Image
QGraphicsScene is a great Qt component allowing to develop full graphics applications (like game for example) in a very easy way. As additional feature is possible to insert a QWidget based object inside the scene through the QGraphicsProxyWidget item.

Qt Snippet: QPushButton with word wrap feature

Image
Qt have two main classes to use as button widget, QPushButton and QToolButton. These classes made the job in a very good way but both miss the word wrap feature. If the button width is not enough for show the entire button text the string is cutted out on sides and this is not a good effect. Word wrap feature allow the control to automatically move part of the text in a new line for allow full view.

Qt Snippet: QLabel with text shadow

Image
In case you want to show your text labels a little more "beautiful" to see a little trick is to add shadow to text and create a 3D text like. In the CSS standard set exist a tag called text-shadow able to apply such effect automatically. Unfortunately this feature is not supported by the Qt QSS stylesheet set so we need to found another way.

Qt Snippet: Use QScroller with QScrollArea

Image
In case you are developing a Qt app for mobile device you'll have the "problem" to manage widgets that need to be scrolled for show data inside. In Desktop system this work is done by using scrollbars or the wheel mouse event but in mobile system you can not use same ways. Instead the touch event is the only way the user have to scroll your widget.

Qt Snippet: " Painter not active " error

Image
If you subclass a widget control and try to repaint the content by overriding the paintEvent() method you could experiment, for some specific type of Qt widgets, the error " Painter not active ". This error come up during program execution when try to create the QPainter object for draw the widget content.

Linux Snippet: include a static library inside another static library

Image
The linux static library format .a is basically only an archive of compiled object files. If you are developing a linux static library that use external functions coming from another static library you need to release both libraries (your library just developed and the second library you get functions from) for allow the final executable to compile correctly.

Qt Snippet: random number generator

Image
In case you need to get a random number Qt provide the "classic" pseudo random generator based to an initial seed number. A pseudo random number is a simply algorithm able to generate a list of different numbers based to an initial number value called "seed".

Android: take a screenshot of a view

Image
There are some different ways to take a screenshot of a view. Here some code snippets ready to use in your app. The basic concept consists in render the content of the view into a bitmap.

Qt Snippet: use stylesheet in a QWidget derived class

Image
If you derive your class directly from QWidget object and want to apply some stylesheet tags for customize interface you'll find that your stylesheet settings will not work.

Qt Snippet: Set background color of a widget

Image
Is possible to easily set the background color of a widget by changing the palette of widget itself.

Qt Snippet: Remove all rows from QTableWidget

Image
QTableWidget is the Qt widget that, as the name suggest, show a table composed by cells able to contain both native field like text or icon and also more complex widgets like listbox, checkbox and so on.