Results 1 to 7 of 7

Thread: PyQt5 Questions

  1. #1
    Join Date
    Jan 2017
    Posts
    3

    Default PyQt5 Questions

    Hello,

    I've been using PyQt5 for a few applications successfully. However, when trying to set up a web browser, I got the error message "Argument has unexpected type QUrl" on this line.

    Qt Code:
    1. self.webView.load(self, url)
    To copy to clipboard, switch view to plain text mode 

    One of the ways I tried to fix this was by reinstalling PyQt5. After doing so I started getting the error message "ImportError: No Module named 'PyQt5.PyGui
    instead. I've tried reinstalling Anaconda, replacing PyQt5 with version 5.6, and switching the tutorial's opening line to "From PyQt5 import *", which leads to the error "NameError: name QWidget is not defined". I'm using Python 3.5 on Windows 7 64-bit. Here's the tutorial I'm trying to follow:

    Qt Code:
    1. import sys
    2. from PyQt5.PyGui import *
    3. class MyBrowser(QWidget):
    4. def __init__(self, parent = None):
    5. super(MyBrowser, self).__init__(parent)
    6. self.createLayout()
    7. self.createConnection()
    8. def search(self):
    9. address = str(self.addressBar.text())
    10. if address:
    11. if address.find('://') == -1:
    12. address = 'http://' + address
    13. url = QUrl(address)
    14. kwargs = {}
    15. self.webView.load(self, url)
    16. def createLayout(self):
    17. self.setWindowTitle("keakon's browser")
    18. self.addressBar = QLineEdit()
    19. self.goButton = QPushButton("&GO")
    20. bl = QHBoxLayout()
    21. bl.addWidget(self.addressBar)
    22. bl.addWidget(self.goButton)
    23. self.webView = QWebView()
    24. layout = QVBoxLayout()
    25. layout.addLayout(bl)
    26. layout.addWidget(self.webView)
    27. self.setLayout(layout)
    28. def createConnection(self):
    29. self.addressBar.returnPressed.connect(self.search)
    30. self.addressBar.returnPressed.connect(self.addressBar.selectAll)
    31. self.goButton.clicked.connect(self.search)
    32. self.goButton.clicked.connect(self.addressBar.selectAll)
    33. app = QApplication(sys.argv)
    34. browser = MyBrowser()
    35. browser.show()
    36. sys.exit(app.exec_())
    To copy to clipboard, switch view to plain text mode 

    Can anyone help me with these errors or direct me to a site where I can learn what's causing them? I'm not sure how to set up PyQt5 so that it will work again or how to fix the webView function for my computer. Thanks in advance for any help provided.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQt5 Questions

    Why are you passsing two arguments to load()?

    Cheers,
    _

  3. #3
    Join Date
    Jan 2017
    Posts
    3

    Default Re: PyQt5 Questions

    Oops, that line is supposed to have just the url parameter. I tried adding self because the python error said that two parameters were needed, but neither version of the method worked.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQt5 Questions

    Hmm, QWebView definitely has a load(QUrl) method.

    Maybe Python has a problem with the overload? I.e. that in C++ there are two methods with the same name an different arguments?

    Cheers,
    _

  5. #5
    Join Date
    Jan 2017
    Posts
    3

    Default Re: PyQt5 Questions

    The error I'm getting in the console window says that the method accepts (self, url). Is there something I can put as the first parameter that might fix things?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: PyQt5 Questions

    Hmm, "self" would be the webview for a method of the webview, maybe
    Qt Code:
    1. self.webView.load(self.webview, url)
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: PyQt5 Questions

    Line 2 of the code won't get past the Python parser because the module is called PyQt5.QtGui.
    Fix that and then
    Qt Code:
    1. Traceback (most recent call last):
    2. File "code.py", line 3, in <module>
    3. class MyBrowser(QWidget):
    4. NameError: name 'QWidget' is not defined
    To copy to clipboard, switch view to plain text mode 
    because you need the PyQt5.QtWidget module. Then
    Qt Code:
    1. Traceback (most recent call last):
    2. File "code.py", line 35, in <module>
    3. browser = MyBrowser()
    4. File "code.py", line 7, in __init__
    5. self.createLayout()
    6. File "code.py", line 24, in createLayout
    7. self.webView = QWebView()
    8. NameError: name 'QWebView' is not defined
    To copy to clipboard, switch view to plain text mode 
    will need PyQt5.QtWebkitWidgets module.

Similar Threads

  1. Question about PyQt5 and QtCreator.
    By robgeek in forum Newbie
    Replies: 1
    Last Post: 7th October 2016, 00:19
  2. PyQt5 tutorials
    By riverbee in forum General Discussion
    Replies: 0
    Last Post: 5th August 2016, 02:42
  3. PyQt5 chart
    By ecce in forum Newbie
    Replies: 2
    Last Post: 24th April 2016, 15:06
  4. How can I install pyQt5
    By prachi kamble in forum Installation and Deployment
    Replies: 0
    Last Post: 4th June 2015, 13:13
  5. PyQt5 QPixmap
    By ChrisOfBristol in forum Newbie
    Replies: 4
    Last Post: 4th April 2015, 22:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.