Tuesday, March 25, 2014

Using QML with C++

Source code here

Recently I stumbled onto an example where the front end of a small application was written in QML and the backend was done in C++. That was the exact thing I was searching for and it provided a great example of how to get QML and C++ working together.

Lets start with the qml: 

//--------------------------------------------------------------------------
// SSH key generator UI

import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0
import QtQuick.Dialogs 1.0
import com.ics.demo 1.0

Tuesday, March 18, 2014

A tale of specificity

I try to be perfect. And I don't feel right till I have finished something completely. So this following tale relates to the relation of specificity and perfection. 

The current project I am working on has a list of lineEdits that I have put into a scrollarea. 

 
This image shows what I was out to achieve. 
First task was to get the scrollarea right. There I encountered first hurdle. See, the thing is the scrolled widget has a fixed size but here the size changes depending on the no of lineEdits added to the scroll Area. At first I settled on a fixed size and put in a spacer. But it wasn't perfect. There were some edge cases where that failed.
So after a lot of thinking I settled on a minimum size, and set size constraint to SetMinimumSize. Later when I added one widget I would increase minimum size and this proved to be a good solution.


Next step was to increase scrollbar width for use on touch screen. I hunted some CSS on net that let me increase the scrollbar width and style it to be usable on a touch screen. 




The one mistake I did was, I applied the style to scroll area. And this above screen was the result. After going through the code and much more thinking, I understood that I have to be specific. I needed to apply the style only to scrollbar. That meant I have to hunt for the scrollbar object. Some more internetz provided me with verticalScrollBar() function. So I applied the style to it and voila!!! 
I achieved my perfect scrollarea implementation!!!

Thursday, March 13, 2014

Another QScrollBar style

Stumbled onto this nice QScrollBar style:

QString styleString="QScrollBar:vertical {"
    "    border: 1px solid #999999;"
    "    background:white;"
    "    width:30px;    "
    "    margin: 0px 0px 0px 0px;"
    "}"
    "QScrollBar::handle:vertical {"
    "    background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
    "    stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));"
    "    min-height: 0px;"
    ""
    "}"
    "QScrollBar::add-line:vertical {"
    "    background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
    "    stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));"
    "    height: 0px;"
    "    subcontrol-position: bottom;"
    "    subcontrol-origin: margin;"
    "}"
    "QScrollBar::sub-line:vertical {"
    "    background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
    "    stop: 0  rgb(32, 47, 130), stop: 0.5 rgb(32, 47, 130),  stop:1 rgb(32, 47, 130));"
    "    height: 0px;"
    "    subcontrol-position: top;"
    "    subcontrol-origin: margin;"
    "}"
    "";
setStyleSheet(styleString);

Gives us following scrollbar: 


Friday, March 7, 2014

Building Qt5 on CentOS 6.3

I am using following method to build Qt5 on CentOS6.3.
Make two dir's. Extract Qt source in source dir. Keep following script in home dir. Execute it from there.

Also go through configure, make and make install phases one-by-one.

#!/bin/sh
export QTBUILD=/home/user/qtsource/qt-everywhere-opensource-build-5.0.2
export QTSOURCE=/home/user/qtsource/qt-everywhere-opensource-src-5.0.2
cd $QTBUILD
$QTSOURCE/configure -opensource -confirm-license -qt-sql-psql -platform linux-g++ -prefix /opt/Qt-5.0.2 -nomake examples -nomake tests -no-gtkstyle
#make -j4 all
#make install
cd -