Hello, i know there is alot post about context menu but i still can't handle it...
so: iam trying to make context menu but only in treeview and columnview, was sitting, reading and trying for 3hours now and i still can't manage to do it, any help?
#include "mainwindow.h"
#include <QtGui>
MainWindow
::MainWindow ( QWidget* parent
){
setupUi ( this );
dirModel->setReadOnly(true);
treeView1->setModel(dirModel);
treeView1->setAcceptDrops(true);
treeView1->setDragEnabled(true);
columnView1->setModel(dirModel);
columnView1->setAcceptDrops(true);
columnView1->setDragEnabled(true);
treeView2->setModel(dirModel);
treeView2->setAcceptDrops(true);
treeView2->setDragEnabled(true);
columnView2->setModel(dirModel);
columnView2->setAcceptDrops(true);
columnView2->setDragEnabled(true);
connect(actionDrzewko, SIGNAL(triggered()), this, SLOT(slotPage1()));
connect(actionKolumny, SIGNAL(triggered()), this, SLOT(slotPage2()));
connect(actionDrzewko_2, SIGNAL(triggered()), this, SLOT(slotPage3()));
connect(actionKolumny_2, SIGNAL(triggered()), this, SLOT(slotPage4()));
}
MainWindow::~MainWindow()
{}
void MainWindow::slotPage1()
{
stackedWidget->setCurrentIndex(0);
stacked1comboBox->setCurrentIndex(0);
}
void MainWindow::slotPage2()
{
stackedWidget->setCurrentIndex(1);
stacked1comboBox->setCurrentIndex(1);
}
void MainWindow::slotPage3()
{
stackedWidget_2->setCurrentIndex(0);
stacked2comboBox->setCurrentIndex(0);
}
void MainWindow::slotPage4()
{
stackedWidget_2->setCurrentIndex(1);
stacked2comboBox->setCurrentIndex(1);
}
{
menu.addAction(actionNowy);
menu.addAction(actionKopiuj);
menu.addAction(actionWytnij);
menu.addAction(actionWklej);
menu.exec(event->globalPos());
}
#include "mainwindow.h"
#include <QtGui>
MainWindow::MainWindow ( QWidget* parent )
: QMainWindow ( parent )
{
setupUi ( this );
dirModel = new QDirModel(QStringList(), QDir::AllEntries |QDir::NoDotAndDotDot , QDir::Name | QDir::IgnoreCase);
dirModel->setReadOnly(true);
treeView1->setModel(dirModel);
treeView1->setAcceptDrops(true);
treeView1->setDragEnabled(true);
columnView1->setModel(dirModel);
columnView1->setAcceptDrops(true);
columnView1->setDragEnabled(true);
treeView2->setModel(dirModel);
treeView2->setAcceptDrops(true);
treeView2->setDragEnabled(true);
columnView2->setModel(dirModel);
columnView2->setAcceptDrops(true);
columnView2->setDragEnabled(true);
connect(actionDrzewko, SIGNAL(triggered()), this, SLOT(slotPage1()));
connect(actionKolumny, SIGNAL(triggered()), this, SLOT(slotPage2()));
connect(actionDrzewko_2, SIGNAL(triggered()), this, SLOT(slotPage3()));
connect(actionKolumny_2, SIGNAL(triggered()), this, SLOT(slotPage4()));
}
MainWindow::~MainWindow()
{}
void MainWindow::slotPage1()
{
stackedWidget->setCurrentIndex(0);
stacked1comboBox->setCurrentIndex(0);
}
void MainWindow::slotPage2()
{
stackedWidget->setCurrentIndex(1);
stacked1comboBox->setCurrentIndex(1);
}
void MainWindow::slotPage3()
{
stackedWidget_2->setCurrentIndex(0);
stacked2comboBox->setCurrentIndex(0);
}
void MainWindow::slotPage4()
{
stackedWidget_2->setCurrentIndex(1);
stacked2comboBox->setCurrentIndex(1);
}
void MainWindow::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
menu.addAction(actionNowy);
menu.addAction(actionKopiuj);
menu.addAction(actionWytnij);
menu.addAction(actionWklej);
menu.exec(event->globalPos());
}
To copy to clipboard, switch view to plain text mode
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include "ui_QTManagerUI.h"
class MainWindow
: public QMainWindow,
private Ui
::MainWindow{
Q_OBJECT
public:
MainWindow
( QWidget* parent
= 0 );
~MainWindow();
private:
private slots:
void slotPage1();
void slotPage2();
void slotPage3();
void slotPage4();
protected:
};
#endif
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QWidget>
#include "ui_QTManagerUI.h"
class QDirModel;
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow ( QWidget* parent = 0 );
~MainWindow();
private:
QDirModel *dirModel;
private slots:
void slotPage1();
void slotPage2();
void slotPage3();
void slotPage4();
protected:
void contextMenuEvent(QContextMenuEvent *event);
};
#endif
To copy to clipboard, switch view to plain text mode
edit: expamle of making new file, copying, cutting and pasting would be nice too
Bookmarks