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

Copy from QLineEdit using Pop up menu

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 2.7k 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 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
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on 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 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 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

          jsulmJ D 2 Replies Last reply
          0
          • Q Qt Enthusiast

            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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 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

              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 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

              • Login

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