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. QAction.setMenu is deprecated, what is the recommended alternative?
Forum Updated to NodeBB v4.3 + New Features

QAction.setMenu is deprecated, what is the recommended alternative?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 993 Views 1 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.
  • ralienppR Offline
    ralienppR Offline
    ralienpp
    wrote on last edited by
    #1

    I'm migrating a Python desktop application from Qt5 to Qt6 (i.e. from PySide2 to PySide6). The old code has some calls to QAction.setMenu(...), which is not supported in the newer version, as I get AttributeError: 'PySide6.QtGui.QAction' object has no attribute 'setMenu' when running the program.

    Although issue PYSIDE-1627 is about this, my understanding is that it is Python-specific. However, the general documentation also points out that this function is deprecated. While other functions discussed on that page come with remarks such as "use X in module Y instead", setMenu does not.

    I'd like to understand whether there is a plan for resolving it in the future versions of PySide, or if one is supposed to take another approach altogether.

    Pl45m4P 1 Reply Last reply
    0
    • ralienppR ralienpp

      I'm migrating a Python desktop application from Qt5 to Qt6 (i.e. from PySide2 to PySide6). The old code has some calls to QAction.setMenu(...), which is not supported in the newer version, as I get AttributeError: 'PySide6.QtGui.QAction' object has no attribute 'setMenu' when running the program.

      Although issue PYSIDE-1627 is about this, my understanding is that it is Python-specific. However, the general documentation also points out that this function is deprecated. While other functions discussed on that page come with remarks such as "use X in module Y instead", setMenu does not.

      I'd like to understand whether there is a plan for resolving it in the future versions of PySide, or if one is supposed to take another approach altogether.

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @ralienpp

      What's your use-case?
      You could replace your QAction with a "real" QMenu or a QPushButton... Most people often mistaken that QAction has no graphical interface (as you can imagine from the name "action").
      Only if you place a QAction in a menuBar or something like that, it creates a graphical representation of it.... using a QWidget.... and most of the time... a QPushButton.
      I think they removed it, because it doesn't make too much sense and just causes confusion about what QAction really is.

      Edit:
      My theory could be wrong... but to confirm:

      • https://doc.qt.io/qt-6/qpushbutton.html#setMenu

      For example, QPushButton::setMenu is still legit :))


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • ralienppR Offline
        ralienppR Offline
        ralienpp
        wrote on last edited by
        #3

        Thanks for your feedback! If I replace the QAction with a QPushButton, I run into a problem later, where several actions are used in .addActions(...) of a widget derived from QFrame.

        It is a rather big legacy application, and I have no full awareness of what it is doing, because I'm not porting my own code and I don't know what the end result ought to look like. Thus, I don't have the foresight to understand what other parts are affected if I change a thing.

        So I was hoping someone could shed some light on QAction.setMenu, which would allow me to make progress by dealing with one piece of the puzzle at a time.

        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