I'm using PyQt and understand enough OOP to get by comfortably in Python. However, the documentation and useful forum posts are all in C++. I know that the best route would probably be to just re-learn C++. I'm trying but It's taking a long time to sift through tutorials and find the information that I need, mostly because I don't understand enough of the terminology to know where to look.
In a particular forum post there is a section in a method of a class implementation that reads:
void SetTextInteraction(bool on, bool selectAll = false)
{
if(on && textInteractionFlags() == Qt::NoTextInteraction)
{
// switch on editor mode:
setTextInteractionFlags(Qt::TextEditorInteraction);
// manually do what a mouse click would do else:
setFocus(Qt::MouseFocusReason); // this gives the item keyboard focus
setSelected(true); // this ensures that itemChange() gets called when we click out of the item
if(selectAll) // option to select the whole text (e.g. after creation of the TextItem)
{
QTextCursor c = textCursor();
c.select(QTextCursor::Document);
setTextCursor(c);
}
}
else if(!on && textInteractionFlags() == Qt::TextEditorInteraction)
{
// turn off editor mode:
setTextInteractionFlags(Qt::NoTextInteraction);
// deselect text (else it keeps gray shade):
QTextCursor c = this->textCursor();
c.clearSelection();
this->setTextCursor(c);
clearFocus();
}
}
The part I don't understand is here:
QTextCursor c = textCursor();
c.select(QTextCursor::Document);
setTextCursor(c);
What would be the equivalent Python code for this specific section? For some reason I thought the first line might be c = QTextCursor.textCursor()
in that result of the method textCursor
from the QTextCursor
class is being assigned to c
, but it seems that there is no textCursor
method. Also I'm having trouble understanding what is going on here:
QTextCursor c = this->textCursor();
c.clearSelection();
this->setTextCursor(c);
An explanation of what is going on in words would be useful as this would help with the terminology bit. A recommendation on some resources to go through to understand these specific pieces of code would be appreciated as well.