All jobs

Fix "AttributeError: type object 'Qt' has no attribute 'AlignCenter'" When Moving to PyQt6

Yes. An agent ports every Qt enum, exec_ call and Matplotlib backend name in your PyQt5 app to PyQt6, drives the window offscreen to prove it, and runs your tests.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

PyQt6 made every Qt enum fully scoped. In PyQt5, QtCore.Qt.AlignCenter is a plain attribute; in PyQt6 6.12.0 it is QtCore.Qt.AlignmentFlag.AlignCenter, and the old spelling raises AttributeError: type object 'Qt' has no attribute 'AlignCenter' the moment a widget's setAlignment runs. The same rule renames QMessageBox.Information to QMessageBox.Icon.Information and QMessageBox.Ok to QMessageBox.StandardButton.Ok, and the exec_ methods are gone: a PyQt6 QApplication and QMessageBox have exec only. Matplotlib's Qt binding follows the same move, from the Qt5Agg backend and backend_qt5agg to QtAgg and backend_qtagg.

In a desktop tool like hrosicka/QuadraticEquationSolver, requirements.txt pins PyQt5==5.15.9, matplotlib==3.8.0, numpy==1.26.0 and pytest==7.3.1, and a GitHub workflow installs that file and runs python -m pytest Tests/ -v on Python 3.10 to 3.12. main.py is 400 lines: it imports widgets, QIntValidator, QIcon and QPixmap from PyQt5, calls matplotlib.use("Qt5Agg") on line 28, sets alignment thirteen times between lines 129 and 206 with QtCore.Qt.AlignLeft, AlignRight and AlignCenter, builds its error dialog on line 231 with QMessageBox(QMessageBox.Information, title, message, buttons=QMessageBox.Ok, parent=self) and shows it with messagebox.exec_() on line 234, and creates the application and window at module level before app.exec(). canvas.py imports FigureCanvasQTAgg from backend_qt5agg. The five tests in Tests/test_quadratic_equation.py cover the solver class alone and never import Qt.

The agent reproduces both sides offscreen, since the sandbox has no display: it installs the Qt platform libraries the offscreen backend needs, sets QT_QPA_PLATFORM=offscreen, and runs the module with the PyQt5 pin to confirm the window builds. Then it installs PyQt6 and runs the file with only the import names changed: it stops at line 129 on AlignLeft, the first enum used, which is why the error people search for names whichever alignment their code reaches first. From there it lists every scoped-enum access, exec_ call and backend name with a grep rather than fixing them one failure at a time.

The port is thirteen alignment flags, the two QMessageBox enums, one exec_, the backend string and the backend module. To prove it without clicking, the agent loads the module with the event loop stripped, fills the three coefficient fields with 1, minus 3 and 2, calls the window's display method and reads the labels back: the equation x<sup>2</sup>-3x+2=0, roots 2.0 and 1.0, discriminant 1, and an alignment value of 132 on the centred label. The same drive on the PyQt5 pin gives the same labels, so the port changed nothing visible. requirements.txt moves to PyQt6, the workflow is unchanged, and pytest still passes its five tests.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "This PyQt5 app fails on PyQt6 with AttributeError: type object 'Qt' has no attribute 'AlignCenter'. The sandbox has no display: install the system libraries the Qt offscreen platform needs and set QT_QPA_PLATFORM=offscreen for every run. First install the pinned PyQt5 requirements and show the window builds; then install PyQt6 in a second environment and run the app with only the import package renamed, capturing the first AttributeError with its line. Grep for every unscoped Qt enum (Qt.Align*, QMessageBox icons and buttons, any other Qt.* constant), every exec_ call and every Qt5 backend name in Matplotlib imports, and list them with file and line. Port each to the PyQt6 form, checking each new name against the installed PyQt6 rather than from memory, and move the Matplotlib backend to QtAgg. Prove it offscreen: load the main module without starting its event loop, fill the inputs with a known equation, call the method that solves it and print the result labels, on both the PyQt5 pin and PyQt6. Update requirements.txt to PyQt6, run the existing tests, and open a pull request with the list of renamed names and both offscreen transcripts.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

A pull request that changes the main window file, the canvas module and requirements.txt. The description opens with the first failure on PyQt6, line and enum named, and a table of every renamed name: the thirteen alignment flags, the message-box icon and button, the exec_ call and the two backend names, each with its file, line and PyQt6 form.

Below that are the two offscreen transcripts, the PyQt5 pin and the PyQt6 port, each printing the same equation, roots, discriminant and alignment value, followed by the pytest run. The session's record keeps the library installs, the environment variable on every command and the grep output the table was built from.

Before merging, a reviewer checks that the dialog's icon and button still match the originals, that the deployment or packaging step installs PyQt6's Qt libraries where the old PyQt5 wheels were bundled, and whether the stylesheet in style.qss has selectors that Qt 6 draws differently.

Run it on every new PyQt5 app queued for PyQt6

A team moving a set of internal tools off PyQt5 starts one run per repository from a script, one request each with that repository in resources, and reviews the ports as they arrive. Give each a request_id that is a UUID v5 of the repository name, so a retried delivery returns the run that already started instead of opening a second pull request.

Where the move is driven by a dependency bump, a bot sender never fires an automation's github trigger, so give the automation a webhook trigger and add a workflow step on the bump that runs when its title names PyQt6 and posts the pull request number to the trigger's URL with Authorization: Bearer and the trigger's secret; the event lands after the prompt, and the run ports the app against the release in that pull request and pushes the port onto the same branch or opens its own.

The use case this job follows, with its automation and trigger: Fix a bug from an alert.

Why run it on Rush?

A GUI port is hard to prove in CI because the usual proof is a person clicking. The agent instead installs the offscreen platform, drives the window from code and reads its labels back on both toolkits, which takes a Linux box with the right libraries and two Python environments. In a Rush sandbox that setup is the agent's own disk, and the machine is gone when the run ends.

What comes back is a comparison, not a screenshot: the same inputs producing the same labels before and after, plus the full list of renamed names. A team with several PyQt5 tools starts one run per repository with the same request, up to the key's max_concurrent limit at once, and the rest queue.

Frequently asked questions

Why does my error name AlignLeft when I searched for AlignCenter?

Because PyQt6 raises on the first unscoped enum the code reaches, and that depends on widget order. In the example the first setAlignment call uses AlignLeft on line 129, so that is the name in the traceback even though AlignCenter appears eight times later. The agent lists them all from a grep rather than fixing them one traceback at a time.

Is exec_ gone for every class?

On the installed PyQt6 6.12.0, QApplication and QMessageBox have exec and no exec_. The agent checks each class the code calls rather than assuming, and in the example the application already used exec() while the message box still used exec_().

Does Matplotlib need to change too?

Yes, in two places: matplotlib.use("Qt5Agg") becomes "QtAgg", and the canvas module imports FigureCanvasQTAgg from matplotlib.backends.backend_qtagg, which serves both PyQt5 and PyQt6. The agent confirms the module imports under the installed Matplotlib before changing the code.

How can the agent test a window without a screen?

With Qt's offscreen platform plugin, selected by QT_QPA_PLATFORM=offscreen, which needs a few system libraries the agent installs first. It then loads the module with the event loop removed, sets the input fields, calls the solve method and reads the labels, on PyQt5 and PyQt6 alike. The existing unit tests do not need any of this because they never import Qt.

More jobs like this: Fix a bug from an alert

Keep reading