Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Copy from QLineEdit using Pop up menu
Forum Updated to NodeBB v4.3 + New Features

Copy from QLineEdit using Pop up menu

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt Enthusiast
    wrote on 12 Jun 2017, 12:27 last edited by
    #1

    Thanks One more thing , Can I customise the Pop menu in which I have only copy

    I do not want menu items
    Undo,Redo, Cut ,Paste ,SelectAll

    I only want Copy in my Right mouse button popup menu . COuld you please provide the sameple for it

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Eddy
      wrote on 12 Jun 2017, 13:41 last edited by
      #2

      this topic is forked from a previous one

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qt Enthusiast
        wrote on 12 Jun 2017, 15:48 last edited by
        #3

        QLabel* CountLabel = new QLabel(tr(" count:"));
        QLineEdit* countValueLabel = new QLineEdit(QString("% 1").arg(count));
        countValueLabel->setStyleSheet("background: rgb(236,236,236); border: 0 px;");
        countValueLabel->setBuddy(countValueLabel );

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          Qt Enthusiast
          wrote on 13 Jun 2017, 05:59 last edited by
          #4

          class customisedLineEdit: public QLineEdit {

          }

          customisedLineEdit::customisedLineEdit(QString string)
          {
          setText(string);
          setReadOnly(true);
          setStyleSheet("background: rgb(236,236,236); border: 0px;");
          setContextMenuPolicy(Qt::CustomContextMenu);
          }

          void customisedLineEdit::contextMenuEvent(QContextMenuEvent event) {
          printf("\n here in contextMenu:");
          QMenu
          menu = createStandardContextMenu();
          QAction* copyAction = new IN_CURRENT_POOL QAction("Copy",this);
          menu->addAction(copyAction);
          copyAction->setShortcut(tr("Ctrl+C"));
          connect(copyAction,SIGNAL(triggered()),this,SLOT(copy()));
          menu->exec(event->globalPos());

          delete menu;
          event->accept();

          }

          I do not get any menu on RMB . Could you suggest how to get only copy in ContextMenu for QlinedEdit

          J D 2 Replies Last reply 13 Jun 2017, 06:40
          0
          • Q Qt Enthusiast
            13 Jun 2017, 05:59

            class customisedLineEdit: public QLineEdit {

            }

            customisedLineEdit::customisedLineEdit(QString string)
            {
            setText(string);
            setReadOnly(true);
            setStyleSheet("background: rgb(236,236,236); border: 0px;");
            setContextMenuPolicy(Qt::CustomContextMenu);
            }

            void customisedLineEdit::contextMenuEvent(QContextMenuEvent event) {
            printf("\n here in contextMenu:");
            QMenu
            menu = createStandardContextMenu();
            QAction* copyAction = new IN_CURRENT_POOL QAction("Copy",this);
            menu->addAction(copyAction);
            copyAction->setShortcut(tr("Ctrl+C"));
            connect(copyAction,SIGNAL(triggered()),this,SLOT(copy()));
            menu->exec(event->globalPos());

            delete menu;
            event->accept();

            }

            I do not get any menu on RMB . Could you suggest how to get only copy in ContextMenu for QlinedEdit

            J Online
            J Online
            jsulm
            Lifetime Qt Champion
            wrote on 13 Jun 2017, 06:40 last edited by
            #5

            @Qt-Enthusiast said in Copy from QLineEdit using Pop up menu:

            void customisedLineEdit::contextMenuEvent(QContextMenuEvent event)

            It must be

            void customisedLineEdit::contextMenuEvent(QContextMenuEvent *event) 
            

            as you can see here http://doc.qt.io/qt-5/qtwidgets-mainwindows-menus-example.html
            Is contextMenuEvent called?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • Q Qt Enthusiast
              13 Jun 2017, 05:59

              class customisedLineEdit: public QLineEdit {

              }

              customisedLineEdit::customisedLineEdit(QString string)
              {
              setText(string);
              setReadOnly(true);
              setStyleSheet("background: rgb(236,236,236); border: 0px;");
              setContextMenuPolicy(Qt::CustomContextMenu);
              }

              void customisedLineEdit::contextMenuEvent(QContextMenuEvent event) {
              printf("\n here in contextMenu:");
              QMenu
              menu = createStandardContextMenu();
              QAction* copyAction = new IN_CURRENT_POOL QAction("Copy",this);
              menu->addAction(copyAction);
              copyAction->setShortcut(tr("Ctrl+C"));
              connect(copyAction,SIGNAL(triggered()),this,SLOT(copy()));
              menu->exec(event->globalPos());

              delete menu;
              event->accept();

              }

              I do not get any menu on RMB . Could you suggest how to get only copy in ContextMenu for QlinedEdit

              D Offline
              D Offline
              Devopia53
              wrote on 13 Jun 2017, 06:56 last edited by
              #6

              @Qt-Enthusiast

              When Qt::CustomContextMenu is set on the widget, contextMenuEvent() handler is not called. Instead QWidget::customContextMenuRequested() signal emitted.

              Removed setContextMenuPolicy(Qt::CustomContextMenu) or like this:

              connect(this, &MyLineEdit::customContextMenuRequested, [=](const QPoint &pos){
                  QMenu *menu = createStandardContextMenu();
                  menu->addAction(tr("My Menu Item"));
                  menu->exec(mapToGlobal(pos));
                  delete menu;
              });
              
              1 Reply Last reply
              0

              1/6

              12 Jun 2017, 12:27

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved