Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 23rd, 2005, 04:14 AM
Hajo Molegraaf
Guest
 
Posts: n/a
Default 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();
}
 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles