Results 1 to 3 of 3

Thread: Context menu

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    4
    Thanks
    2

    Default Context menu

    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?

    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QtGui>
    3.  
    4. MainWindow::MainWindow ( QWidget* parent )
    5. : QMainWindow ( parent )
    6. {
    7. setupUi ( this );
    8.  
    9.  
    10. dirModel = new QDirModel(QStringList(), QDir::AllEntries |QDir::NoDotAndDotDot , QDir::Name | QDir::IgnoreCase);
    11. dirModel->setReadOnly(true);
    12.  
    13. treeView1->setModel(dirModel);
    14. treeView1->setAcceptDrops(true);
    15. treeView1->setDragEnabled(true);
    16.  
    17.  
    18. columnView1->setModel(dirModel);
    19. columnView1->setAcceptDrops(true);
    20. columnView1->setDragEnabled(true);
    21.  
    22. treeView2->setModel(dirModel);
    23. treeView2->setAcceptDrops(true);
    24. treeView2->setDragEnabled(true);
    25.  
    26. columnView2->setModel(dirModel);
    27. columnView2->setAcceptDrops(true);
    28. columnView2->setDragEnabled(true);
    29.  
    30. connect(actionDrzewko, SIGNAL(triggered()), this, SLOT(slotPage1()));
    31. connect(actionKolumny, SIGNAL(triggered()), this, SLOT(slotPage2()));
    32. connect(actionDrzewko_2, SIGNAL(triggered()), this, SLOT(slotPage3()));
    33. connect(actionKolumny_2, SIGNAL(triggered()), this, SLOT(slotPage4()));
    34. }
    35.  
    36.  
    37. MainWindow::~MainWindow()
    38. {}
    39.  
    40.  
    41.  
    42. void MainWindow::slotPage1()
    43. {
    44. stackedWidget->setCurrentIndex(0);
    45. stacked1comboBox->setCurrentIndex(0);
    46. }
    47.  
    48. void MainWindow::slotPage2()
    49. {
    50. stackedWidget->setCurrentIndex(1);
    51. stacked1comboBox->setCurrentIndex(1);
    52. }
    53.  
    54. void MainWindow::slotPage3()
    55. {
    56. stackedWidget_2->setCurrentIndex(0);
    57. stacked2comboBox->setCurrentIndex(0);
    58. }
    59.  
    60. void MainWindow::slotPage4()
    61. {
    62. stackedWidget_2->setCurrentIndex(1);
    63. stacked2comboBox->setCurrentIndex(1);
    64. }
    65.  
    66. void MainWindow::contextMenuEvent(QContextMenuEvent *event)
    67. {
    68. QMenu menu(this);
    69.  
    70. menu.addAction(actionNowy);
    71. menu.addAction(actionKopiuj);
    72. menu.addAction(actionWytnij);
    73. menu.addAction(actionWklej);
    74. menu.exec(event->globalPos());
    75. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QWidget>
    6. #include "ui_QTManagerUI.h"
    7.  
    8. class QDirModel;
    9.  
    10.  
    11. class MainWindow : public QMainWindow, private Ui::MainWindow
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. MainWindow ( QWidget* parent = 0 );
    17. ~MainWindow();
    18.  
    19. private:
    20. QDirModel *dirModel;
    21.  
    22.  
    23. private slots:
    24. void slotPage1();
    25. void slotPage2();
    26. void slotPage3();
    27. void slotPage4();
    28.  
    29. protected:
    30. void contextMenuEvent(QContextMenuEvent *event);
    31.  
    32. };
    33.  
    34.  
    35. #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
    Last edited by dejvis; 19th September 2009 at 18:15.

Similar Threads

  1. problem with Context Menu in QTableWidget
    By andreime in forum Newbie
    Replies: 6
    Last Post: 7th September 2015, 08:44
  2. Context Menu on QTableWidget
    By ankurjain in forum Qt Programming
    Replies: 9
    Last Post: 17th December 2009, 09:52
  3. Custom context menu in QTreeView
    By ttvo in forum Qt Programming
    Replies: 5
    Last Post: 3rd April 2009, 22:29
  4. Shortcut key for context menu
    By darshan.hardas in forum Qt Programming
    Replies: 1
    Last Post: 28th December 2008, 20:32
  5. Replies: 4
    Last Post: 25th June 2007, 20:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.