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. AddWidget - Type error
Qt 6.11 is out! See what's new in the release blog

AddWidget - Type error

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 2 Posters 3.1k 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.
  • A Offline
    A Offline
    Achab61
    wrote on last edited by
    #1

    I'm trying to add a Widget to a vertical box (named 'qvb_grafico' based on Vertical layout) creted with QT Designer. In the line "self.window.qvb_grafico.addWidget(self.canvas)" I'm getting the error: Type error: argument 1 has unexpected type 'FigureCanvasAgg'

    Any suggestion is welcome

    Here below the piece of code:

    from PyQt5 import uic
    import matplotlib.pyplot as plt
    from matplotlib.backends.backend_qt5agg import FigureCanvasAgg as FigureCanvas
    from numpy import *

    class Grafico:

    code_text
    ```numeroPunti = 200                                  
        def __init__(self, window):    
            self.window=window                                                                                    
            self.figura=plt.figure()                       
            self.ax=self.figura.add_subplot(111)            
            self.canvas=FigureCanvas(self.figura)          
            self.window.qvb_grafico.addWidget(self.canvas)  
            self.statoGriglia=False
    ....
    JonBJ 1 Reply Last reply
    0
    • A Achab61

      I'm trying to add a Widget to a vertical box (named 'qvb_grafico' based on Vertical layout) creted with QT Designer. In the line "self.window.qvb_grafico.addWidget(self.canvas)" I'm getting the error: Type error: argument 1 has unexpected type 'FigureCanvasAgg'

      Any suggestion is welcome

      Here below the piece of code:

      from PyQt5 import uic
      import matplotlib.pyplot as plt
      from matplotlib.backends.backend_qt5agg import FigureCanvasAgg as FigureCanvas
      from numpy import *

      class Grafico:

      code_text
      ```numeroPunti = 200                                  
          def __init__(self, window):    
              self.window=window                                                                                    
              self.figura=plt.figure()                       
              self.ax=self.figura.add_subplot(111)            
              self.canvas=FigureCanvas(self.figura)          
              self.window.qvb_grafico.addWidget(self.canvas)  
              self.statoGriglia=False
      ....
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Achab61 said in AddWidget - Type error:

          self.canvas=FigureCanvas(self.figura)          
          self.window.qvb_grafico.addWidget(self.canvas) 
      

      addWidget() presumably requires a QWidget. Is FigureCanvas/FigureCanvasAgg a QWidget?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Achab61
        wrote on last edited by
        #3

        I found the problem. I replaced FigureCanvasAgg with FigureCanvasQTAgg in the import statement and it works.

        Thanks for your help

        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