Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to use ok and cancel button in PyQt6 inside MessageBox
Forum Updated to NodeBB v4.3 + New Features

How to use ok and cancel button in PyQt6 inside MessageBox

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 3.0k 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.
  • Q Offline
    Q Offline
    qtDevOps
    wrote on last edited by qtDevOps
    #1
    msgBox = QtWidgets.QMessageBox()
            msgBox.setIcon(QtWidgets.QMessageBox.Information)
            msgBox.setText(msg)
            msgBox.setWindowTitle("New Window")
            if dialogFlag == "ok":
                msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok)
            elif dialogFlag == "okcancel":
                msgBox.setStandardButtons(
                    QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel
                )
            response = msgBox.exec()
            return response
    

    The above code works perfectly fine with PyQt5 but it doesn't work with PyQt6 and throws this error.

    msgBox.setIcon(QtWidgets.QMessageBox.Information)
    AttributeError: type object 'QMessageBox' has no attribute 'Information'
    

    The error is same with Ok and Canel button as well.

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Wild guess: try QtWidgets.QMessageBox.Icon.Information and QtWidgets.QMessageBox.StandardButton.Ok

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • Q Offline
        Q Offline
        qtDevOps
        wrote on last edited by
        #3

        Thank you, It worked!

        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