Home > OS >  Why PyQt5 Qt class cannot access its own members?
Why PyQt5 Qt class cannot access its own members?

Time:10-21

I have some problems working with PyQt5.QtCore Qt class. While creating .py file from .ui there are multiple errors connected with Qt class. Using Qt class in my main program also doesn't bring any results.

self.DateNum = QtWidgets.QLineEdit(self.centralwidget)
self.DateNum.setGeometry(QtCore.QRect(90, 280, 140, 30))
self.DateNum.setCursor(QtGui.QCursor(QtCore.Qt.IBeamCursor))
self.DateNum.setFocusPolicy(QtCore.Qt.ClickFocus)
self.DateNum.setContextMenuPolicy(QtCore.Qt.DefaultContextMenu)
self.DateNum.setAcceptDrops(False)

While QtWidgets are working properly, all QtCore.Qt gives me an error like - "Cannot access member "ClickFocus" for type 'Type[Qt]' Member "ClickFocus" is unknown". Here is my import:

from PyQt5 import QtCore, QtGui, QtWidgets

I tried different solutions from the internet, but nothing worked for me. From the error seems like Qt class is just empty... but its not.

Sorry if duplicated.

CodePudding user response:

Thanks to Matt Clarke for moving me in right direction. So basically when .py file was created from .ui it created wrong code. I just added to all error places enum titles and everything worked. Looked for it here:

https://doc.qt.io/qt-6/qt.html

Now the same code looks like this:

self.DateNum = QtWidgets.QLineEdit(self.centralwidget)
self.DateNum.setGeometry(QtCore.QRect(90, 280, 140, 30))
self.DateNum.setCursor(QtGui.QCursor(QtCore.Qt.CursorShape.IBeamCursor))
self.DateNum.setFocusPolicy(QtCore.Qt.FocusPolicy.ClickFocus)
self.DateNum.setContextMenuPolicy(QtCore.Qt.ContextMenuPolicy.DefaultContextMenu)
self.DateNum.setAcceptDrops(False)
  • Related