Skip to content

PythonQt.QtGui.QUndoStack · declarations 001

Back to PythonQt.QtGui.QUndoStack

active instance-attribute

active: Any

Qt 5 reference:

active : bool

This property holds the active status of this stack.

An application often has multiple undo stacks, one for each opened document. The active stack is the one associated with the currently active document. If the stack belongs to a QUndoGroup, calls to QUndoGroup::undo() or QUndoGroup::redo() will be forwarded to this stack when it is active. If the QUndoGroup is watched by a QUndoView, the view will display the contents of this stack when it is active. If the stack does not belong to a QUndoGroup, making it active has no effect.

It is the programmer's responsibility to specify which stack is active by calling setActive(), usually when the associated document window receives focus.

Access functions:

bool isActive() const
void setActive(bool active \= true)

See also QUndoGroup.

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#active

beginMacro

beginMacro(text: str) -> None

X.beginMacro(text)

Supplemental documentation: Qt 5 reference:

void QUndoStack::beginMacro(const QString \&text)

Begins composition of a macro command with the given text description.

An empty command described by the specified text is pushed on the stack. Any subsequent commands pushed on the stack will be appended to the empty command's children until endMacro() is called.

Calls to beginMacro() and endMacro() may be nested, but every call to beginMacro() must have a matching call to endMacro().

While a macro is being composed, the stack is disabled. This means that:

The stack becomes enabled and appropriate signals are emitted when endMacro() is called for the outermost macro.

stack.beginMacro("insert red text");
stack.push(new InsertText(document, idx, text));
stack.push(new SetColor(document, idx, text.length(), Qt::red));
stack.endMacro(); // indexChanged() is emitted

This code is equivalent to:

QUndoCommand *insertRed = new QUndoCommand(); // an empty command
insertRed->setText("insert red text");

new InsertText(document, idx, text, insertRed); // becomes child of insertRed
new SetColor(document, idx, text.length(), Qt::red, insertRed);

stack.push(insertRed);

See also endMacro().

Upstream PySide2 reference signatures (binding differences may apply):

beginMacro(self, text: str) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#beginMacro

canRedo instance-attribute

canRedo: bool

Qt 5 reference:

canRedo : const bool

This property holds whether this stack can redo.

This property indicates whether or not there is a command that can be redone.

This property was introduced in Qt 5.12.

Access functions:

bool canRedo() const

Notifier signal:

void canRedoChanged(bool canRedo)

See also canRedo(), index(), and canUndo().

bool QUndoStack::canRedo() const

Returns true if there is a command available for redo; otherwise returns false.

This function returns false if the stack is empty or if the top command on the stack has already been redone.

Synonymous with index() \=\= count().

Note: Getter function for property canRedo.

See also index() and canUndo().

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#canRedo

canRedoChanged

canRedoChanged(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.canRedoChanged; argument details are not documented.

Supplemental documentation: Qt 5 reference:

[signal] void QUndoStack::canRedoChanged(bool canRedo)

This signal is emitted whenever the value of canRedo() changes. It is used to enable or disable the redo action returned by createRedoAction(). canRedo specifies the new value.

Note: Notifier signal for property canRedo.

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#canRedoChanged

canUndo instance-attribute

canUndo: bool

Qt 5 reference:

canUndo : const bool

This property holds whether this stack can undo.

This property indicates whether or not there is a command that can be undone.

This property was introduced in Qt 5.12.

Access functions:

bool canUndo() const

Notifier signal:

void canUndoChanged(bool canUndo)

See also canUndo(), index(), and canRedo().

bool QUndoStack::canUndo() const

Returns true if there is a command available for undo; otherwise returns false.

This function returns false if the stack is empty, or if the bottom command on the stack has already been undone.

Synonymous with index() \=\= 0.

Note: Getter function for property canUndo.

See also index() and canRedo().

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#canUndo

canUndoChanged

canUndoChanged(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.canUndoChanged; argument details are not documented.

Supplemental documentation: Qt 5 reference:

[signal] void QUndoStack::canUndoChanged(bool canUndo)

This signal is emitted whenever the value of canUndo() changes. It is used to enable or disable the undo action returned by createUndoAction(). canUndo specifies the new value.

Note: Notifier signal for property canUndo.

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#canUndoChanged

clean instance-attribute

clean: Any

Qt 5 reference:

clean : const bool

This property holds the clean status of this stack.

This property indicates whether or not the stack is clean. For example, a stack is clean when a document has been saved.

This property was introduced in Qt 5.12.

Access functions:

bool isClean() const

Notifier signal:

void cleanChanged(bool clean)

See also isClean(), setClean(), resetClean(), and cleanIndex().

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#clean

cleanChanged

cleanChanged(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.cleanChanged; argument details are not documented.

Supplemental documentation: Qt 5 reference:

[signal] void QUndoStack::cleanChanged(bool clean)

This signal is emitted whenever the stack enters or leaves the clean state. If clean is true, the stack is in a clean state; otherwise this signal indicates that it has left the clean state.

Note: Notifier signal for property clean.

See also isClean() and setClean().

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#cleanChanged

cleanIndex

cleanIndex() -> int

X.cleanIndex() -> int

Supplemental documentation: Qt 5 reference:

int QUndoStack::cleanIndex() const

Returns the clean index. This is the index at which setClean() was called.

A stack may not have a clean index. This happens if a document is saved, some commands are undone, then a new command is pushed. Since push() deletes all the undone commands before pushing the new command, the stack can't return to the clean state again. In this case, this function returns -1. The -1 may also be returned after an explicit call to resetClean().

See also isClean() and setClean().

Upstream PySide2 reference signatures (binding differences may apply):

cleanIndex(self) -> int

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#cleanIndex

clear

clear() -> None

X.clear()

Supplemental documentation: Qt 5 reference:

void QUndoStack::clear()

Clears the command stack by deleting all commands on it, and returns the stack to the clean state.

Commands are not undone or redone; the state of the edited object remains unchanged.

This function is usually used when the contents of the document are abandoned.

See also QUndoStack().

Upstream PySide2 reference signatures (binding differences may apply):

clear(self) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#clear

command

command(index: int) -> Any

X.command(index) -> PythonQt.QtGui.QUndoCommand

Supplemental documentation: Qt 5 reference:

const QUndoCommand *QUndoStack::command(int index) const

Returns a const pointer to the command at index.

This function returns a const pointer, because modifying a command, once it has been pushed onto the stack and executed, almost always causes corruption of the state of the document, if the command is later undone or redone.

This function was introduced in Qt 4.4.

See also QUndoCommand::child().

Upstream PySide2 reference signatures (binding differences may apply):

command(self, index: int) -> PySide2.QtWidgets.QUndoCommand

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#command

count

count() -> int

X.count() -> int

Supplemental documentation: Qt 5 reference:

int QUndoStack::count() const

Returns the number of commands on the stack. Macro commands are counted as one command.

See also index(), setIndex(), and command().

Upstream PySide2 reference signatures (binding differences may apply):

count(self) -> int

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#count

createRedoAction

createRedoAction(parent: Any, prefix: str) -> Any

X.createRedoAction(parent, prefix) -> PythonQt.QtGui.QAction

Supplemental documentation: Qt 5 reference:

QAction *QUndoStack::createRedoAction(QObject *parent, const QString \&prefix \= QString()) const

Creates an redo QAction object with the given parent.

Triggering this action will cause a call to redo(). The text of this action is the text of the command which will be redone in the next call to redo(), prefixed by the specified prefix. If there is no command available for redo, this action will be disabled.

If prefix is empty, the default template "Redo %1" is used instead of prefix. Before Qt 4.8, the prefix "Redo" was used by default.

See also createUndoAction(), canRedo(), and QUndoCommand::text().

Upstream PySide2 reference signatures (binding differences may apply):

createRedoAction(self, parent: PySide2.QtCore.QObject, prefix: str=...) -> PySide2.QtWidgets.QAction

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#createRedoAction

createUndoAction

createUndoAction(parent: Any, prefix: str) -> Any

X.createUndoAction(parent, prefix) -> PythonQt.QtGui.QAction

Supplemental documentation: Qt 5 reference:

QAction *QUndoStack::createUndoAction(QObject *parent, const QString \&prefix \= QString()) const

Creates an undo QAction object with the given parent.

Triggering this action will cause a call to undo(). The text of this action is the text of the command which will be undone in the next call to undo(), prefixed by the specified prefix. If there is no command available for undo, this action will be disabled.

If prefix is empty, the default template "Undo %1" is used instead of prefix. Before Qt 4.8, the prefix "Undo" was used by default.

See also createRedoAction(), canUndo(), and QUndoCommand::text().

Upstream PySide2 reference signatures (binding differences may apply):

createUndoAction(self, parent: PySide2.QtCore.QObject, prefix: str=...) -> PySide2.QtWidgets.QAction

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#createUndoAction

destroyed

destroyed(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.destroyed; argument details are not documented.

endMacro

endMacro() -> None

X.endMacro()

Supplemental documentation: Qt 5 reference:

void QUndoStack::endMacro()

Ends composition of a macro command.

If this is the outermost macro in a set nested macros, this function emits indexChanged() once for the entire macro command.

See also beginMacro().

Upstream PySide2 reference signatures (binding differences may apply):

endMacro(self) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#endMacro

index

index() -> int

X.index() -> int

Supplemental documentation: Qt 5 reference:

int QUndoStack::index() const

Returns the index of the current command. This is the command that will be executed on the next call to redo(). It is not always the top-most command on the stack, since a number of commands may have been undone.

See also setIndex(), undo(), redo(), and count().

Upstream PySide2 reference signatures (binding differences may apply):

index(self) -> int

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#index

indexChanged

indexChanged(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.indexChanged; argument details are not documented.

Supplemental documentation: Qt 5 reference:

[signal] void QUndoStack::indexChanged(int idx)

This signal is emitted whenever a command modifies the state of the document. This happens when a command is undone or redone. When a macro command is undone or redone, or setIndex() is called, this signal is emitted only once.

idx specifies the index of the current command, ie. the command which will be executed on the next call to redo().

See also index() and setIndex().

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#indexChanged

isActive

isActive() -> bool

X.isActive() -> bool

Upstream PySide2 reference signatures (binding differences may apply):

isActive(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#isActive

isClean

isClean() -> bool

X.isClean() -> bool

Supplemental documentation: Qt 5 reference:

bool QUndoStack::isClean() const

If the stack is in the clean state, returns true; otherwise returns false.

Note: Getter function for property clean.

See also setClean() and cleanIndex().

Upstream PySide2 reference signatures (binding differences may apply):

isClean(self) -> bool

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#isClean

objectNameChanged

objectNameChanged(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.objectNameChanged; argument details are not documented.

push

push(cmd: Any) -> None

X.push(cmd)

Supplemental documentation: Qt 5 reference:

void QUndoStack::push(QUndoCommand *cmd)

Pushes cmd on the stack or merges it with the most recently executed command. In either case, executes cmd by calling its redo() function.

If cmd's id is not -1, and if the id is the same as that of the most recently executed command, QUndoStack will attempt to merge the two commands by calling QUndoCommand::mergeWith() on the most recently executed command. If QUndoCommand::mergeWith() returns true, cmd is deleted.

After calling QUndoCommand::redo() and, if applicable, QUndoCommand::mergeWith(), QUndoCommand::isObsolete() will be called for cmd or the merged command. If QUndoCommand::isObsolete() returns true, then cmd or the merged command will be deleted from the stack.

In all other cases cmd is simply pushed on the stack.

If commands were undone before cmd was pushed, the current command and all commands above it are deleted. Hence cmd always ends up being the top-most on the stack.

Once a command is pushed, the stack takes ownership of it. There are no getters to return the command, since modifying it after it has been executed will almost always lead to corruption of the document's state.

See also QUndoCommand::id() and QUndoCommand::mergeWith().

Upstream PySide2 reference signatures (binding differences may apply):

push(self, cmd: PySide2.QtWidgets.QUndoCommand) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#push

redo

redo() -> None

X.redo()

Supplemental documentation: Qt 5 reference:

[slot] void QUndoStack::redo()

Redoes the current command by calling QUndoCommand::redo(). Increments the current command index.

If the stack is empty, or if the top command on the stack has already been redone, this function does nothing.

If QUndoCommand::isObsolete() returns true for the current command, then the command will be deleted from the stack. Additionally, if the clean index is greater than or equal to the current command index, then the clean index is reset.

See also undo() and index().

Upstream PySide2 reference signatures (binding differences may apply):

redo(self) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#redo

redoText instance-attribute

redoText: str

Qt 5 reference:

redoText : const QString

This property holds the redo text of the next command that is redone.

This property holds the text of the command which will be redone in the next call to redo().

This property was introduced in Qt 5.12.

Access functions:

QString redoText() const

Notifier signal:

void redoTextChanged(const QString \&redoText)

See also redoText(), QUndoCommand::actionText(), and undoText().

QString QUndoStack::redoText() const

Returns the text of the command which will be redone in the next call to redo().

Note: Getter function for property redoText.

See also QUndoCommand::actionText() and undoText().

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#redoText

redoTextChanged

redoTextChanged(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.redoTextChanged; argument details are not documented.

Supplemental documentation: Qt 5 reference:

[signal] void QUndoStack::redoTextChanged(const QString \&redoText)

This signal is emitted whenever the value of redoText() changes. It is used to update the text property of the redo action returned by createRedoAction(). redoText specifies the new text.

Note: Notifier signal for property redoText.

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#redoTextChanged

resetClean

resetClean() -> None

X.resetClean()

Supplemental documentation: Qt 5 reference:

[slot] void QUndoStack::resetClean()

Leaves the clean state and emits cleanChanged() if the stack was clean. This method resets the clean index to -1.

This is typically called in the following cases, when a document has been:

  • created basing on some template and has not been saved, so no filename has been associated with the document yet.
  • restored from a backup file.
  • changed outside of the editor and the user did not reload it.

This function was introduced in Qt 5.8.

See also isClean(), setClean(), and cleanIndex().

Upstream PySide2 reference signatures (binding differences may apply):

resetClean(self) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#resetClean

setActive

setActive(active: bool) -> None

X.setActive(active)

Upstream PySide2 reference signatures (binding differences may apply):

setActive(self, active: bool=...) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#setActive

setClean

setClean() -> None

X.setClean()

Supplemental documentation: Qt 5 reference:

[slot] void QUndoStack::setClean()

Marks the stack as clean and emits cleanChanged() if the stack was not already clean.

This is typically called when a document is saved, for example.

Whenever the stack returns to this state through the use of undo/redo commands, it emits the signal cleanChanged(). This signal is also emitted when the stack leaves the clean state.

See also isClean(), resetClean(), and cleanIndex().

Upstream PySide2 reference signatures (binding differences may apply):

setClean(self) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#setClean

setIndex

setIndex(idx: int) -> None

X.setIndex(idx)

Supplemental documentation: Qt 5 reference:

[slot] void QUndoStack::setIndex(int idx)

Repeatedly calls undo() or redo() until the current command index reaches idx. This function can be used to roll the state of the document forwards of backwards. indexChanged() is emitted only once.

See also index(), count(), undo(), and redo().

Upstream PySide2 reference signatures (binding differences may apply):

setIndex(self, idx: int) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#setIndex

setUndoLimit

setUndoLimit(limit: int) -> None

X.setUndoLimit(limit)

Upstream PySide2 reference signatures (binding differences may apply):

setUndoLimit(self, limit: int) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#setUndoLimit

text

text(idx: int) -> str

X.text(idx) -> str

Supplemental documentation: Qt 5 reference:

QString QUndoStack::text(int idx) const

Returns the text of the command at index idx.

See also beginMacro().

Upstream PySide2 reference signatures (binding differences may apply):

text(self, idx: int) -> str

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#text

undo

undo() -> None

X.undo()

Supplemental documentation: Qt 5 reference:

[slot] void QUndoStack::undo()

Undoes the command below the current command by calling QUndoCommand::undo(). Decrements the current command index.

If the stack is empty, or if the bottom command on the stack has already been undone, this function does nothing.

After the command is undone, if QUndoCommand::isObsolete() returns true, then the command will be deleted from the stack. Additionally, if the clean index is greater than or equal to the current command index, then the clean index is reset.

See also redo() and index().

Upstream PySide2 reference signatures (binding differences may apply):

undo(self) -> None

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#undo

undoLimit instance-attribute

undoLimit: int

Qt 5 reference:

undoLimit : int

This property holds the maximum number of commands on this stack.

When the number of commands on a stack exceedes the stack's undoLimit, commands are deleted from the bottom of the stack. Macro commands (commands with child commands) are treated as one command. The default value is 0, which means that there is no limit.

This property may only be set when the undo stack is empty, since setting it on a non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack prints a warning and does nothing.

This property was introduced in Qt 4.3.

Access functions:

int undoLimit() const
void setUndoLimit(int limit)

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#undoLimit

undoText instance-attribute

undoText: str

Qt 5 reference:

undoText : const QString

This property holds the undo text of the next command that is undone.

This property holds the text of the command which will be undone in the next call to undo().

This property was introduced in Qt 5.12.

Access functions:

QString undoText() const

Notifier signal:

void undoTextChanged(const QString \&undoText)

See also undoText(), QUndoCommand::actionText(), and redoText().

QString QUndoStack::undoText() const

Returns the text of the command which will be undone in the next call to undo().

Note: Getter function for property undoText.

See also QUndoCommand::actionText() and redoText().

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#undoText

undoTextChanged

undoTextChanged(*args: Any, **kwargs: Any) -> Any

Native PythonQt.QtGui.QUndoStack.undoTextChanged; argument details are not documented.

Supplemental documentation: Qt 5 reference:

[signal] void QUndoStack::undoTextChanged(const QString \&undoText)

This signal is emitted whenever the value of undoText() changes. It is used to update the text property of the undo action returned by createUndoAction(). undoText specifies the new text.

Note: Notifier signal for property undoText.

Source: https://doc.qt.io/archives/qt-5.15/qundostack.html#undoTextChanged