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. Problem with ContextMenu

Problem with ContextMenu

Scheduled Pinned Locked Moved Unsolved General and Desktop
24 Posts 6 Posters 1.7k Views
  • 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.
  • B Offline
    B Offline
    Brad1111
    wrote on last edited by Brad1111
    #1

    Hi,
    I have a 'simple' problem but I cant understand whats wrong.
    I basically have a Qtextedit, and I want to get rid of the contextmenu, or change it.
    I tried everything and literally nothing works, it looks like it calls some other function or I dunno.

    I tried to re implement contextmenuevent, but its not called.
    I tried to set the policy to custom and connect the signal to a function, but its not called.
    i also tried the setcontextmenu policy to nocontextmenu. Nothing seems to be even called whenever I click on my textedit and I get this menu with Select, Select all, etc options.

    Anyone knows what Im not seing ? Its really a simple example, I can create a brand new textedit and I have the same issue so I dont think I need to copy paste 200 lines of code.
    Also, it might be interesting to note Im testing this on Mobile.

    thanks for help

    1 Reply Last reply
    0
    • JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      Did you start from e.g. https://forum.qt.io/topic/115347/context-menu or https://www.qtcentre.org/threads/35166-extend-the-standard-context-menu-of-qtextedit ?

      1 Reply Last reply
      0
      • B Offline
        B Offline
        Brad1111
        wrote on last edited by
        #3

        I read all of these but as I said, I dont enter these functions, so it doesnt really matter what I put in there, adding actions etc.
        I Put a Qdebug in each of the slots, or reimplemented virtual member functions, and they dont get called at all it seems.
        Is there something else than contextmenu that displays the options to select text ?

        jsulmJ 1 Reply Last reply
        0
        • B Brad1111

          I read all of these but as I said, I dont enter these functions, so it doesnt really matter what I put in there, adding actions etc.
          I Put a Qdebug in each of the slots, or reimplemented virtual member functions, and they dont get called at all it seems.
          Is there something else than contextmenu that displays the options to select text ?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Brad1111 Did you set https://doc.qt.io/qt-6/qwidget.html#contextMenuPolicy-prop ?

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

          1 Reply Last reply
          1
          • B Offline
            B Offline
            Brad1111
            wrote on last edited by
            #5

            @jsulm Yes, I tried both Qt::NoContextMenu, Qt::PreventContextMenu, and it still shows with 0 difference.
            I also tried the custommenu, and the slot connected to custommenurequested doesnt get called.

            JonBJ 1 Reply Last reply
            0
            • B Brad1111

              @jsulm Yes, I tried both Qt::NoContextMenu, Qt::PreventContextMenu, and it still shows with 0 difference.
              I also tried the custommenu, and the slot connected to custommenurequested doesnt get called.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Brad1111
              Please copy & paste a minimal example of compliable code showing the unexpected behaviour. The smaller the better :)
              Also state what platform you are on and what version of Qt.

              1 Reply Last reply
              0
              • B Offline
                B Offline
                Brad1111
                wrote on last edited by Brad1111
                #7

                Just create a new QTextedit, with the flag set to texteditable because I dont want it to be readonly.
                and then whatever I try wouldnt work. whether it be custommenu, or nomenu. It doesnt require any specific setting.
                as an example, ui->mynewtextedit->setContextMenuPolicy( Qt::PreventContextMenu);
                Qt6 with iOs - which might be the problem ?

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Works fine for me:

                  int main(int argc, char* argv[])
                  {
                      QApplication a(argc, argv);
                      QTextEdit edit;
                      edit.setContextMenuPolicy(Qt::NoContextMenu);
                      edit.show();
                      return a.exec();
                  }
                  

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  B 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    Works fine for me:

                    int main(int argc, char* argv[])
                    {
                        QApplication a(argc, argv);
                        QTextEdit edit;
                        edit.setContextMenuPolicy(Qt::NoContextMenu);
                        edit.show();
                        return a.exec();
                    }
                    
                    B Offline
                    B Offline
                    Brad1111
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher Did you test this on iOs/Android too or on a computer ?

                    Christian EhrlicherC 1 Reply Last reply
                    0
                    • B Brad1111

                      @Christian-Ehrlicher Did you test this on iOs/Android too or on a computer ?

                      Christian EhrlicherC Offline
                      Christian EhrlicherC Offline
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @Brad1111 I don't have any apple related env stuff here (and I will never have).

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      B 1 Reply Last reply
                      1
                      • Christian EhrlicherC Christian Ehrlicher

                        @Brad1111 I don't have any apple related env stuff here (and I will never have).

                        B Offline
                        B Offline
                        Brad1111
                        wrote on last edited by
                        #11

                        @Christian-Ehrlicher The real question is whether you're testing this on a mobile environment, Android or IOS, no matter. Or desktop? If it works on Desktop I wouldnt be surprised.
                        I need someone to test it on mobile, because it could be the issue imo.

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          CPPUIX
                          wrote on last edited by CPPUIX
                          #12

                          Yeah, it doesn't work on mobile, I still get a context menu. Android, Qt 6.7.1. You need a solution specific to mobile.

                          Used Christian's MRE:

                          int main(int argc, char* argv[])
                          {
                              QApplication a(argc, argv);
                              QTextEdit edit;
                              edit.setContextMenuPolicy(Qt::NoContextMenu);
                              edit.show();
                              return a.exec();
                          }
                          
                          B 1 Reply Last reply
                          1
                          • Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            You should create a bug report if it's still reproducable with Qt6.8

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            1
                            • C CPPUIX

                              Yeah, it doesn't work on mobile, I still get a context menu. Android, Qt 6.7.1. You need a solution specific to mobile.

                              Used Christian's MRE:

                              int main(int argc, char* argv[])
                              {
                                  QApplication a(argc, argv);
                                  QTextEdit edit;
                                  edit.setContextMenuPolicy(Qt::NoContextMenu);
                                  edit.show();
                                  return a.exec();
                              }
                              
                              B Offline
                              B Offline
                              Brad1111
                              wrote on last edited by Brad1111
                              #14

                              @Abderrahmene_Rayene thanks. Im a bit surprised theres such a 'bug' , but I couldnt understand how to fix it.

                              Do you guys think this could be fixed by QT team within, say, a couple of months or is it most likely to take much longer ?

                              @Christian-Ehrlicher I know its a stupid question, but where can I report a bug ?

                              1 Reply Last reply
                              0
                              • C Offline
                                C Offline
                                CPPUIX
                                wrote on last edited by
                                #15

                                Try to work around it, perhaps through the event system, idk, just shooting in the dark here. It's probably native stuff (also shooting in the dark).

                                And since this is Qt Widgets on mobile, that will probably make it very low priority, because it's not QML/Qt Quick. I'm also shooting in the dark here. Sorry.

                                You can report bugs here (not shooting in the dark): https://bugreports.qt.io/

                                But test with Qt 6.8 first, as Chrisitan suggested. I doubt it's "fixed" there.

                                B 1 Reply Last reply
                                0
                                • C CPPUIX

                                  Try to work around it, perhaps through the event system, idk, just shooting in the dark here. It's probably native stuff (also shooting in the dark).

                                  And since this is Qt Widgets on mobile, that will probably make it very low priority, because it's not QML/Qt Quick. I'm also shooting in the dark here. Sorry.

                                  You can report bugs here (not shooting in the dark): https://bugreports.qt.io/

                                  But test with Qt 6.8 first, as Chrisitan suggested. I doubt it's "fixed" there.

                                  B Offline
                                  B Offline
                                  Brad1111
                                  wrote on last edited by
                                  #16

                                  @Abderrahmene_Rayene I posted here because I didnt succeed working around it :D
                                  I would need more details if I am to try another way to get my results i.e. get rid of the contextmenu, because I am not that good with QT.

                                  I currently have qt 6.7 so yea highly doubt it works with 6.8

                                  1 Reply Last reply
                                  0
                                  • C Offline
                                    C Offline
                                    CPPUIX
                                    wrote on last edited by
                                    #17

                                    See if you could make something with this:

                                    • https://qtcentre.org/threads/7718-How-to-disable-context-menu-of-a-toolbar-in-QMainApplication

                                    Try to check if context menu events get called. If not, there's probably nothing you could do. Like you said here:

                                    I tried everything and literally nothing works, it looks like it calls some other function or I dunno.

                                    Except by Android, not other functions.

                                    B 1 Reply Last reply
                                    0
                                    • C CPPUIX

                                      See if you could make something with this:

                                      • https://qtcentre.org/threads/7718-How-to-disable-context-menu-of-a-toolbar-in-QMainApplication

                                      Try to check if context menu events get called. If not, there's probably nothing you could do. Like you said here:

                                      I tried everything and literally nothing works, it looks like it calls some other function or I dunno.

                                      Except by Android, not other functions.

                                      B Offline
                                      B Offline
                                      Brad1111
                                      wrote on last edited by
                                      #18

                                      @Abderrahmene_Rayene I tried to filter and identify events but couldnt find something to make it work, without breaking the whole textedit functionality.
                                      I submitted a bug report.

                                      1 Reply Last reply
                                      0
                                      • C Offline
                                        C Offline
                                        CPPUIX
                                        wrote on last edited by
                                        #19

                                        Yeah, figured.

                                        Could you link to the bug report here? I can't find it.

                                        B 1 Reply Last reply
                                        0
                                        • C CPPUIX

                                          Yeah, figured.

                                          Could you link to the bug report here? I can't find it.

                                          B Offline
                                          B Offline
                                          Brad1111
                                          wrote on last edited by
                                          #20

                                          @Abderrahmene_Rayene QTBUG-130712

                                          1 Reply Last reply
                                          1

                                          • Login

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