Showing posts with label Symbian. Show all posts
Showing posts with label Symbian. Show all posts

Monday, December 27, 2010

Changing the positive & negetive softkeys




Qt menu bar has two menu items, as you would have seen by default left side of the key is “Options” and the right side is “Exit”.
Today we shall see how to change the text of it.
The left key is “Positive Soft key” & the right key is “Negative soft key”. We need to create an action with the positive and negative soft key role and insert to the window, so the keys will get changed.
Ex: For positive soft key:(Left side key)

QAction* Newkey = new QAction("New", this);
Newkey->setSoftKeyRole(QAction::PositiveSoftKey);
this->addAction(Newkey);


Negative soft key: (Right side key)
QAction* close = new QAction("close", this);
close->setSoftKeyRole(QAction::NegativeSoftKey);
this->addAction(close);


Here is the sample code, just put these files in a sample application and run for the results

.cpp file

#include "QT_Softkeys.h"
#include <qmessagebox.h>

QT_Softkeys::QT_Softkeys(QWidget *parent)
    : QMainWindow(parent)
{
        //ui.setupUi(this);
        
    
        QAction* Newkey = new QAction("New", this);
        Newkey->setSoftKeyRole(QAction::PositiveSoftKey);
        this->addAction(Newkey);
        
        QAction* close = new QAction("close", this);
        close->setSoftKeyRole(QAction::NegativeSoftKey);
        connect(close,SIGNAL(triggered()),this,SLOT(closeClickked()));
        this->addAction(close);
                       
        
}

QT_Softkeys::~QT_Softkeys()
{

}

void QT_Softkeys::closeClickked()
        {
        QMessageBox::information(this,"Hi","Hi we r closing");
        QApplication::quit();
        }


Header file

#ifndef QT_SOFTKEYS_H
#define QT_SOFTKEYS_H

#include <QtGui/QMainWindow>
#include "ui_QT_Softkeys.h"

class QT_Softkeys : public QMainWindow
{
    Q_OBJECT

public:
        QT_Softkeys(QWidget *parent = 0);
    ~QT_Softkeys();
    
    public slots:
    void closeClickked();

private:
    Ui::QT_Softkeys ui;
};

#endif // QT_SOFTKEYS_H


Sunday, June 13, 2010

How to add stylesheet for button in Qt




Here i am showing, how to set the button background color from stylesheet.

CustomButton *pushButton = new CustomButton();
pushButton->setStyleSheet(QString::fromUtf8("background-color: rgb(255, 255, 0);"));


How to set background image for button using stylesheet.

CustomButton *pushButton = new CustomButton();
pushButton_2->setStyleSheet(QString::fromUtf8("background-image: url(:/new/prefix1/icon/Smiley.bmp);"));


if you are using Qt GUI for designing, follow up these steps.











How to customize the Button in Qt




In this article,we will see how to customize button.

Qt has provided the option to place any number of Texts and images at desired location over a button, but now i am showing how to place 3 Text and 1 image over a button.

First we need to subclass the Qpushbutton, then override the paintEvent() method. In the paint event method perform the drawing Text, images etc..

sample code is provided here..

//Custom button class
//Qt-articles.blogspot.com

class CustomButton : public QPushButton
{
Q_OBJECT

public:
CustomButton(QWidget *parent = 0);
~CustomButton();

public:
QString FirstName,MiddleName,Lastname;
QImage SimileIcon;
bool IsBkColorEnabled;
QColor Bkclor;

protected:
void paintEvent(QPaintEvent *);

};



//Custom button implimentation file
//Qt-articles.blogspot.com
CustomButton::CustomButton(QWidget *parent)
: QPushButton(parent)
{

}

CustomButton::~CustomButton()
{

}
//Paint event of button
void CustomButton::paintEvent(QPaintEvent *paint)
{
QPushButton::paintEvent(paint);
QPainter p(this);
p.save();

p.drawText(QPoint(100,100),FirstName); //Simple Text.
p.setPen(Qt::blue); //changing the color of pen.
p.setFont(QFont("Arial", 30)); //Changing the font.
p.drawText(QPoint(100,200),MiddleName);
p.drawText(QPoint(100,300),Lastname);
p.drawImage(QPoint(300,300),SimileIcon);
p.restore();
}


How to Add Resources to Project in Qt




Its very simple, follow up these steps.

Create new Qrc file.



New Qrc file looks like this


Add the file to Qrc.



using the Resource file in project.

 ":/new/prefix1/icon/Smiley.bmp"

for example,

QIcon icon;
icon.load(":/new/prefix1/icon/Smiley.bmp");

Note:- Prefix of icon can be changed to your wish.