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