Showing posts with label qtcreator. Show all posts
Showing posts with label qtcreator. Show all posts

2013-03-07

QML Resizable rectangle from scratch


It has been forever since I've posted anything on my blog.  Apologies to my follower...  Meanwhile, I have learned quite a lot about QML and QtQuick over the past 6 months or so.  I will have to go dig through my code and find some snippets that I think will be helpful to those joining the Qt universe.

This is a (relatively) simple Item I created which allows the user to click any one of the four walls and drag it to resize the rectangle.  You can also left click on the rectangle and drag it around.  This example does NOT include any limitations to dragging, so if you can pretty much destroy the rectangle by dragging one wall right over the opposite wall.  However, I thought it best to post something simple rather than something more complicated and hard to read for newcomers.  Relationships between anchors and QML objects can get quite confusing fast, and you have to avoid anchor loops.  This is nothing more than an example of multiple anchors working together which actually works, but is not finished product.  


Maybe someone will get some use out of it.


Cheers!
-----------------------------------------------------------------------------

//import QtQuick 2.0
import QtQuick 1.1

 Item {
    id: resizeRectItem
    property real rectWidth
    property real rectHeight

    rectWidth: rightWall.x - leftWall.x
    rectHeight: bottomWall.y - topWall.y
    //opacity: 1

    Rectangle {
        id: resizeRect
        width: rectWidth
        height: rectHeight
        color: "blue"
        anchors.right: rightWall.left
        anchors.bottom: bottomWall.top
        anchors.top: topWall.bottom
        anchors.left: leftWall.right
    }
    MouseArea {
        id: resizeRectDragMA
        width: rectWidth -5
        height: rectHeight -5
        anchors.centerIn: parent
        drag.target: resizeRectItem
        drag.axis: Drag.XandYAxis

        onPressed: {
            resizeRect.color = "green"
            resizeRectItem.anchors.centerIn = null
        }
        onReleased: {
            resizeRect.color = "blue"
        }
    }

    Rectangle {
        id: topWall
        x: -100
        y: -100
        width: rectWidth
        height: 4
        color: "red"
    }
    MouseArea {
        id: topWallMA
        anchors.fill: topWall
        drag.target: topWall
        drag.axis: Drag.YAxis
        onPressed: {
            leftWall.anchors.top = topWall.bottom
            rightWall.anchors.top = topWall.bottom
        }
    }
    Rectangle {
        id: bottomWall
        x:-100
        y: 100
        width: rectWidth
        height: 4
        color: "purple"
    }
    MouseArea {
        id: bottomWallMA
        anchors.fill: bottomWall
        drag.target: bottomWall
        drag.axis: Drag.YAxis
        onPressed: {
            leftWall.anchors.bottom = bottomWall.top
            rightWall.anchors.bottom = bottomWall.top
        }
    }
    Rectangle {
        id: leftWall
        x: -100
        y: -100
        width: 4
        height: rectHeight
        color: "yellow"
    }
    MouseArea {
        id: leftWallMA
        anchors.fill: leftWall
        drag.target: leftWall
        drag.axis: Drag.XAxis
        onPressed: {
            topWall.anchors.left = leftWall.right
            bottomWall.anchors.left = leftWall.right
        }
    }
    Rectangle {
        id: rightWall
        x: 100
        y: -100
        width: 4
        height: rectHeight
        color: "orange"
    }
    MouseArea {
        id: rightWallMA
        anchors.fill: rightWall
        drag.target: rightWall
        drag.axis: Drag.XAxis
        onPressed: {
            topWall.anchors.right = rightWall.left
            bottomWall.anchors.right = rightWall.left
        }
    }
    states: [
        State {
             name: "hide"
             PropertyChanges {
                 target: resizeRectItem
                 opacity: 0.0
             }
        }
    ]
}

2012-05-29

Install QtCreator 2.5 Linux Fedora from the binary (.bin) download

What I am describing here is kind of noob stuff, but then that's what I do :  kick ass for the noobs every day.

You will need to have already installed the Software Development Kit before you do this.  Currently, on May 29, 2012, the latest version of the Qt SDK is 1.2.1.  You can get the installer here.  For my installation I used the Linux 64 bit Offline Installer.  This will also install QtCreator 2.3.1 as part of the whole package.  Now, since they haven't (yet) released an SDK that includes QtCreator 2.5, you can just grab the binary here and install it yourself.

Download it, it should be about 98mb so it will depend on your connection speed how long it takes.
Open the folder where you downloaded it.
Right click on it.  It should look like this:  qt-creator-linux-x86_64-opensource-2.5.0.bin
Select properties.
Select the permissions tab.
Check the box for "Allow executing file as program."

Now I would just say, "Now double-click on it", but that didn't work for me.  It gave me some error:

Could not display "/home/ultrajones/Downloads/q...x-x86_64-opensource-2.5.0.bin"

The file is of an unknown type

No it isn't.
So open a terminal and CD to the directory where you downloaded it.  Most likely this is the Downloads folder in your Home directory.  When you open a terminal you will already be in the Home directory, so just type:

cd Downloads

And you will be there.
Type:

ls

You will see a list of all the files and folders in that directory.
Somewhere on the list you should see:

qt-creator-linux-x86_64-opensource-2.5.0.bin

Here's a nice trick.  Now type:

./qt-

and hit the tab key.  The terminal should fill out the rest of the name for you, since it is the only thing in the folder with a name starting with "qt-".  Oooh magic.  By the way, the dot ( . ) stands for current directory and the slash ( / ) just tells the terminal to execute the following file.  Now just hit enter and the installer should fire up.  

If it didn't, don't blame me.  I do this for free!  

Cheers!