Qt QAccel question (very basic)



 DEVELOP > c-Plus-Plus > Qt QAccel question (very basic)

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1
Topic: DEVELOP > c-Plus-Plus
User: "Hajo Molegraaf"
Date: 12 Apr 2005 01:10:25 PM
Object: Qt QAccel question (very basic)
Hi,
I'm doing my first steps in Qt programming and there is something that
I don't know how to do. As an excercise I want to write some
filemanager like application and I'm trying to implement copy/paste
features. I have two classes derived from QListView that give me two
views. I want the application to respond to the key CTRL-C or menu
option 'copy' by calling the corresponding 'action_copy' function from
one of the two classes (see below). I probably have to use QAccel but
I don't know how.
What follows is some small source code that has the basics of the
problem. What I want is that if I press CTRL-C in the left view
(belonging to class ViewA), the function ViewA::action_copy is called
and mutatis mutandis for the right view.
Thanks,
Hajo.
#include <qmainwindow.h>
#include <qlistview.h>
#include <qapplication.h>
#include <qsplitter.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qmessagebox.h>
class ViewA : public QListView
{
Q_OBJECT
public:
ViewA( QWidget* parent, const char* name = 0 );
// other function specific to ViewA
public slots:
void action_copy();
};
class ViewB : public QListView
{
Q_OBJECT
public:
ViewB( QWidget* parent, const char* name = 0 );
// other function specific to ViewB
public slots:
void action_copy();
};
class App : public QMainWindow
{
Q_OBJECT
public:
App();
public slots:
void menu_copy();
protected:
ViewA* viewA;
ViewB* viewB;
};
ViewA::ViewA( QWidget* parent, const char* name ) :
QListView(parent,name)
{
addColumn("column");
// something here probably
}
void ViewA::action_copy()
{
QMessageBox::information( this, "ViewA", "ViewA::menu_copy()" );
}
ViewB::ViewB( QWidget* parent, const char* name ) :
QListView(parent,name)
{
addColumn("column");
// something here probably
}
void ViewB::action_copy()
{
QMessageBox::information( this, "ViewB", "ViewB::menu_copy()" );
}
App::App()
{
QPopupMenu *edit = new QPopupMenu( this );
edit->insertItem( "&Copy", this, SLOT(menu_copy()), CTRL+Key_C );
QMenuBar* menu = menuBar();
menu->insertItem( "&Edit", edit );

QSplitter* splitter = new QSplitter( Qt::Horizontal, this );
viewA = new ViewA(splitter);
viewB = new ViewB(splitter);

setCentralWidget(splitter);
}
void App::menu_copy()
{
QMessageBox::information( this, "App", "App::menu_copy()" );
}
int main( int argc, char **argv )
{
QApplication a( argc, argv );
App app;
app.resize( 640, 480 );
a.setMainWidget( &app );
app.show();
return a.exec();
}
.

 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER