Skip to content

Qt for Python

For discussion and questions about Qt for Python (PySide & Shiboken)

3.3k Topics 14.5k Posts
  • crop the image

    Unsolved
    5
    0 Votes
    5 Posts
    478 Views
    SGaistS
    Where in that code is the cropping done ?
  • Multi column context menu

    Unsolved
    7
    0 Votes
    7 Posts
    578 Views
    GrecKoG
    A QTableWidget doesn't seem to be most solution thing for this, you are not presenting data. A QHboxLayout of QVBoxLayout would be the solution I'd try.
  • PyCapsule in Shiboken bindings

    Unsolved
    1
    1 Votes
    1 Posts
    162 Views
    No one has replied
  • Logging

    Unsolved
    2
    0 Votes
    2 Posts
    266 Views
    sierdzioS
    @MasterQ said in Logging: What does the qCWarning, qCDebug, ... do? The first parameter is an object. What object? I could not find a suitable documentation. This is for categorized logging, more info here: https://doc.qt.io/qt-6/qloggingcategory.html. I don't know if it works with Python.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    3 Views
    No one has replied
  • Library conflict when importing PySide6 from C++ embedded Python application

    Unsolved
    2
    0 Votes
    2 Posts
    483 Views
    JonBJ
    @mlperini My 2 cents. Only my assumptions. The pip install of PySide6 is intended for Python use and deliberately standalone/self-contained/isolated from whatever Qt6 you may or may nor have outside on the system. If you have an incompatible version out there it doesn't matter. Conversely the non-Python world just sees what is out there in the system, nothing to do with the Python. So again if they're incompatible it doesn't matter. This works fine for distinct applications. But I can imagine that if you want to mix Python and system/C++ in one process don't you need them to be the exact same version to avoid grief?
  • How to go about creating drag/drop tabs?

    Unsolved
    1
    0 Votes
    1 Posts
    203 Views
    No one has replied
  • modified Qt example editabletreemodel

    Solved
    6
    0 Votes
    6 Posts
    501 Views
    MasterQM
    Oh dear, it's Friday. the isue was that I called i11 = ProjectsTreeItem(["11", "12"]) instead of i11 = ProjectsTreeItem(["11", "12"],i1) I've forgotten to give the parent parameter, which is set to None as default.
  • Is it possible to control where widgets get rendered to?

    Solved
    4
    0 Votes
    4 Posts
    399 Views
    N
    @GrecKo Thanks! That's very helpful~
  • PySide6 in Conda environment: uic automation

    Unsolved
    1
    0 Votes
    1 Posts
    221 Views
    No one has replied
  • 0 Votes
    2 Posts
    301 Views
    jeremy_kJ
    The text description sounds like a QMdiArea
  • How to create a QIcon from a .exe path?

    Solved
    4
    0 Votes
    4 Posts
    352 Views
    M
    @JonB Thanks a lot. Apparently the QFileIconProvider class was removed from PyQt6, but QFileSystemModel can be used instead. Here's the updated code, it now successfully creates a QIcon for .exe icon paths. On my system there's still some application icon paths that aren't being found by the get_installed_apps_from_registry method, or maybe they just don't exist in the registry, so maybe someone will be able to improve upon this code: import sys import os import winreg from PyQt6.QtWidgets import QApplication, QComboBox, QMainWindow from PyQt6.QtGui import QIcon, QFileSystemModel from PyQt6.QtCore import QSize def get_installed_apps_from_registry(registry_path): apps = [] try: reg_key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, registry_path, 0, winreg.KEY_READ) for i in range(0, winreg.QueryInfoKey(reg_key)[0]): try: subkey_name = winreg.EnumKey(reg_key, i) subkey = winreg.OpenKey(reg_key, subkey_name) # Retrieve app name app_name, _ = winreg.QueryValueEx(subkey, "DisplayName") # Retrieve app icon path try: icon_path, _ = winreg.QueryValueEx(subkey, "DisplayIcon") icon_path = icon_path.split(",")[0].strip() # Clean up icon path if not os.path.isfile(icon_path): icon_path = None except FileNotFoundError: icon_path = None # Append app name and icon path to the list apps.append({"name": app_name, "icon": icon_path}) except EnvironmentError: continue finally: subkey.Close() except EnvironmentError: pass return apps def list_installed_apps(): registry_paths = [ r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", r"SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" ] installed_apps = [] for path in registry_paths: installed_apps.extend(get_installed_apps_from_registry(path)) # Remove duplicates and sort unique_apps = {app['name']: app for app in installed_apps if app['name']} sorted_apps = sorted(unique_apps.values(), key=lambda x: x['name']) return sorted_apps class AppComboBox(QMainWindow): def __init__(self, apps): super().__init__() self.setWindowTitle("Installed Applications") self.setGeometry(100, 100, 400, 100) # Create QComboBox self.combo = QComboBox(self) self.combo.setIconSize(QSize(32, 32)) self.combo.setGeometry(50, 20, 300, 40) # Initialize QFileSystemModel to fetch icons self.file_model = QFileSystemModel() # Add apps to combo box with icons for app in apps: icon = self.get_icon(app['icon']) if app['icon'] else QIcon() self.combo.addItem(icon, app['name']) def get_icon(self, icon_path): # Fetches an icon using QFileSystemModel based on file path if icon_path and os.path.isfile(icon_path): index = self.file_model.index(icon_path) return self.file_model.fileIcon(index) return QIcon() # Return an empty icon if path is invalid def main(): # Fetch installed applications apps = list_installed_apps() # Print program name and icon path for app in apps: print(f"Name: {app['name']}") print(f"Icon Path: {app['icon']}") print("-" * 40) # Set up the PyQt6 application app = QApplication(sys.argv) window = AppComboBox(apps) window.show() sys.exit(app.exec()) if __name__ == "__main__": main()
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    8 Views
    No one has replied
  • Stylesheet not applied correctly

    Unsolved
    16
    0 Votes
    16 Posts
    3k Views
    J
    QSS has too much exceptional rules, which makes it hard to use. Hope it could be simplified.
  • Can't set tab order after rearranging widgets

    Unsolved
    13
    0 Votes
    13 Posts
    929 Views
    J
    I made a full release if anyone wants the full context: https://sourceforge.net/projects/inscryption-hydra-tracker/ I hope this thread helps others who find setTabOrder not working for them. It took me a week to figure this out, never give up! Here's the finished sort method: def _sort_cards(self, cards: list) -> None: "Helper method to sort cards into the scrollarea. cards is the sorted list of Card objects to use." # create a temporary widget and reparent all the cards to it: temp_parent = QtWidgets.QWidget() for card in cards: card.setParent(temp_parent) # add all the cards and show the line: for index, card in enumerate(cards): # for some reason adding the card to the layout makes it hidden, so capture and restore that state: hidden = card.isHidden() self.verticalLayout_player_cards.insertWidget(index, card) card.setHidden(hidden) card.show_line() self._hide_top_card_line() Thanks to everyone who helped and responded!
  • Qt Quick plugin?

    Unsolved
    1
    0 Votes
    1 Posts
    116 Views
    No one has replied
  • How to keep QMenu context menu inside my mainscreen?

    Unsolved
    3
    0 Votes
    3 Posts
    282 Views
    B
    @JonB def show_sub_menu_at_position(self): if sistem.isContextShown == 0: sistem.isContextShown = 1 self.item1.exec_(self.mapToGlobal(QPoint(50, 50))) I have changed the method to run for one-time operation, but again failed... The sub-menu moved to 50,50 but after I clicked to another place to hide the context, it crashed...
  • adding as one of multiple widgets in a PyQt6 Window

    Solved
    9
    0 Votes
    9 Posts
    1k Views
    E
    Thanks @SGaist, did that.
  • QTreeView with lots of items is really slow. Can it be optimised or is something buggy?

    Unsolved
    31
    3 Votes
    31 Posts
    7k Views
    I
    @Cipherstream Option #2 is really not a big issue. More Python packages than you'd guess have a compiled component, and Python packaging tools handle that case well by building binary wheels. (As much as anything about the Python packaging ecosystem can be described as "well")
  • 0 Votes
    3 Posts
    440 Views
    JonBJ
    @markleo For IPC you have shared memory, TCP sockets, named pipes, for parent/child processes stdin/stdout, or specifically Qt Remote Objects. All available from Qt and Python.