Skip to content

Language Bindings

You're using Qt with other languages than C++, eh? Post here!
860 Topics 3.4k Posts
  • Problem running pyside2 example in Linux

    Unsolved
    2
    0 Votes
    2 Posts
    673 Views
    CristianMaureiraC

    Hello,
    do you have some logs related to the build process?
    It seems to me that there is a mismatch between Qt and PySide2 versions.

    Which version of Qt did you use?
    and which branch of PySide2?

  • Problems with installing pyside2 on linux

    Solved
    7
    0 Votes
    7 Posts
    2k Views
    SGaistS

    What mistake was it ? It might be useful for other people having the same trouble as you.

  • Problem With JSON value type of data

    Solved
    3
    0 Votes
    3 Posts
    833 Views
    D

    Hi @sierdzio

    Thanks for the reply!

    The API already sends IDs in both formats: int (or double) and string.

    If that is the case I will use strings in my code.

    Thank you very much.

    Regards.

  • 0 Votes
    4 Posts
    1k Views
    SGaistS

    From what's on the report, QtQuick would be a better choice for the UI in that case.

  • Dynamic locale change

    Unsolved
    2
    0 Votes
    2 Posts
    837 Views
    JonBJ

    @spanara
    I would assume you will have to do your steps --- how else would the button know to change its text?

    But with your "many widgets" you should not have to write code for each widget to handle this/update itself. You should be able to loop over all of them doing the updates in one go.

  • 0 Votes
    4 Posts
    1k Views
    SGaistS

    PyQt is a wrapper on top of Qt, what happens within the Qt classes is on the C++ side.

  • Passing arguments from PySide2 to QML.

    Unsolved
    2
    0 Votes
    2 Posts
    3k Views
    D

    @pleaseHelpSteve: What worked for me is using QStringModel as described here https://stackoverflow.com/questions/50609986/how-to-connect-python-and-qml-with-pyside2 (or here http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html)

  • QThread Freezes GUI

    Unsolved
    2
    0 Votes
    2 Posts
    2k Views
    SGaistS

    Hi,

    Looks like there's some problem with the PySide 2 implementation. You should check the bug report system to see if it's something known. If not, please consider opening a new report providing your example and as much details as possible about your current setup.

  • Displaying numbers with QLCDNumber.display() with PyQt5

    Solved
    10
    0 Votes
    10 Posts
    7k Views
    SGaistS

    Since you're using conda, try installing the version that is provided through conda, that will make your environment more coherent.

  • Languist: how to dynamically switch language of all UI?

    Locked Unsolved
    2
    0 Votes
    2 Posts
    666 Views
    SGaistS

    Hi,

    Please don't post the same question in multiple sub-forum. One is enough.

    Duplicate

    Closing this one.

  • How to create a menu with mitil-pages by Pyside2

    Solved
    2
    0 Votes
    2 Posts
    603 Views
    Y

    My god... I thought I have a answer...

    just use this for each widgets I want to create...

    new_widget.show()
  • This topic is deleted!

    Locked Unsolved
    3
    0 Votes
    3 Posts
    5 Views
  • 0 Votes
    3 Posts
    1k Views
    SGaistS

    Hi,

    Just a wild guess but the dialog that you invoke triggers a local event loop that blocks the application flow until you’re done with it. That event loop now processes all the events, so there might be something regarding that.

  • Compiling PythonQt with Qt creator

    2
    0 Votes
    2 Posts
    4k Views
    R

    It is neccessary to run qmake (Build -> Run qmake) after every change, i could be environment variables or any qt project files like prf...

  • 0 Votes
    3 Posts
    15k Views
    P

    I figured it out finally, some things around OOP are still very confusing for me, I guess I need time and more experience to settle all down. Below is a functional example of simple window with two QToolButtons - a regular one and modified one.

    @JonB: I think that there is no difference between using PyQt and PySide, except for import statements, and loading ui, I think that PyQt cannot load ui file directly, it must be converted to py, maybe I'm wrong.

    Now there are four things that bother me:

    how to use regular QtToolButton as a classic button with drop-down menu (see my example), it seems that triggered signal is always called. Is it designed to work that way? If I don't add signal in code than button does nothing? are there any major flaws in my example that should be corrected/fixed? how to "inject" my custom made object into ui at wanted location? In my example I just inserted it inside grid_layout. Can I make a placeholder somehow? Let's say I have a more complicated window with many widgets, for example:

    window.jpg

    and I want to replace that Add Something button with custom one. What would be the best procedure to do this?
    4) is calling GUI directly from a ui XML file smart thing to do or it would be better to convert it to py first?

    My example, program.py, and form.ui:

    #!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Docs """ import os, sys from PySide2 import QtWidgets, QtUiTools class CustomToolButton(QtWidgets.QToolButton): ''' CustomToolButton description ''' def __init__(self, parent=None): ''' Constructor ''' super(CustomToolButton, self).__init__(parent) self.setPopupMode(self.MenuButtonPopup) self.triggered.connect(self.setDefaultAction) return None class Program(QtWidgets.QWidget): ''' Program description ''' def __init__(self, parent=None): ''' Constructor ''' super(Program, self).__init__(parent) self.program_path = os.path.dirname(os.path.realpath(__file__)) self.loader = QtUiTools.QUiLoader() ui_file_path = os.path.join(self.program_path, 'form.ui') self.window = self.loader.load(ui_file_path, parent) self.setup_ui(self.window) return None def setup_ui(self, window): self.grid_layout = window.gridLayout # tool button created in Qt Designer self.tool_btn = window.toolButton ### THIS RUNS EVERY TIME BUTTON IS CLICKED NO MATTER ### WHAT ACTION YOU CHOOSE FROM DROP-DOWN MENU ### IT SEEMS THAT IN THIS CASE YOU CANNOT USE BUTTON LIKE ### CLASSIC BUTTON, ### THEREFORE IT SEEMS THAT "setDefaultAction" MAKES NO SENSE self.tool_btn.triggered.connect(self.clicked_tool_btn) # custom tool button self.custom_tool_btn = CustomToolButton() self.custom_tool_btn.setText('Custom button') self.custom_tool_btn.setMinimumSize(150,50) self.custom_tool_btn.setMaximumSize(150,50) self.grid_layout.addWidget(self.custom_tool_btn) self.define_ui_elements() def define_ui_elements(self): # tool button created in Qt Designer tool_btn_menu = QtWidgets.QMenu(self) tool_btn_menu.addAction('Action 1', self.action1_activated) tool_btn_menu.addAction('Action 2', self.action2_activated) tool_btn_menu.addAction('Action 3', self.action3_activated) tool_btn_default_action = QtWidgets.QAction('Action 1',self) self.tool_btn.setMenu(tool_btn_menu) self.tool_btn.setDefaultAction(tool_btn_default_action) # custom tool button ''' 1) creating actions ''' action1 = QtWidgets.QAction('Action 1', self) action2 = QtWidgets.QAction('Action 2', self) action3 = QtWidgets.QAction('Action 3', self) ''' 2) creating connections ''' action1.triggered.connect(self.action1_activated) action2.triggered.connect(self.action2_activated) action3.triggered.connect(self.action3_activated) ''' 3) creating btn menu ''' custom_tool_btn_menu = QtWidgets.QMenu(self) custom_tool_btn_menu.addAction(action1) custom_tool_btn_menu.addAction(action2) custom_tool_btn_menu.addAction(action3) ''' 4) setting up menu and default action ''' self.custom_tool_btn.setMenu(custom_tool_btn_menu) self.custom_tool_btn.setDefaultAction(action1) ### THIS RUNS EVERY TIME BUTTON IS CLICKED NO MATTER WHAT ACTION YOU CHOOSE FROM DROP-DOWN MENU def clicked_tool_btn(self): # calling action1_activated() because it is default option self.action1_activated() print('Qt Designer button is clicked.') def action1_activated(self): print('Action 1 activated.') def action2_activated(self): print('Action 2 activated.') def action3_activated(self): print('Action 3 activated.') if __name__ == '__main__': program = QtWidgets.QApplication(sys.argv) main_window = Program() main_window.window.show() sys.exit(program.exec_()) <?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Form</class> <widget class="QWidget" name="Form"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="sizePolicy"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> <property name="minimumSize"> <size> <width>400</width> <height>300</height> </size> </property> <property name="maximumSize"> <size> <width>400</width> <height>300</height> </size> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QGridLayout" name="gridLayout"> <item row="1" column="0"> <widget class="QToolButton" name="toolButton"> <property name="minimumSize"> <size> <width>150</width> <height>50</height> </size> </property> <property name="maximumSize"> <size> <width>150</width> <height>50</height> </size> </property> <property name="text"> <string>QtDsgnrBtn</string> </property> <property name="popupMode"> <enum>QToolButton::MenuButtonPopup</enum> </property> </widget> </item> </layout> </widget> <resources/> <connections/> </ui>
  • 0 Votes
    4 Posts
    941 Views
    SGaistS

    That was already clear. The question was: can you reproduce that behaviour easily ?

    Can you share a minimal compilable example showing that behaviour ?

  • Python/PyQt QDialog with connect lambda "leaks"

    Solved
    13
    1 Votes
    13 Posts
    5k Views
    JonBJ

    For the original problem, and https://stackoverflow.com/a/48501804/489865, stating "a connected lambda which references self will not be garbage collected", I received the following code function from the PyQt mailing list. I am not going to use it myself unless I have to (I prefer to rewrite code so as not to use self-referencing lambdas), but I paste it here (untested; and the author states it's for Python 2.7 but should work for Python 3) in case other readers in future might be interested.

    def connect_lambda(bound_signal, self, func, **kw): # It can be used like this: # Instead of # self.editingFinished.connect(lambda: self.whatever()) # do # connect_lambda(self.editingFinished, self, lambda self: self.whatever()) import weakref r = weakref.ref(self) del self num_args = func.__code__.co_argcount - 1 if num_args < 0: raise TypeError('lambda must take at least one argument') def slot(*args): ctx = r() if ctx is not None: if len(args) != num_args: args = args[:num_args] func(ctx, *args) bound_signal.connect(slot, **kw)
  • 3 Votes
    6 Posts
    1k Views
    SGaistS

    Qt Creator is open source, you can modify it at will.

    What @VRonin meant is that the current version of Qt Creator doesn't provide such an option.

    You might want to open a feature request for it.

  • 0 Votes
    4 Posts
    2k Views
    JonBJ

    @nightpoison
    If you are starting out now and choosing to use Qt's regular expressions (I use Python's), you really should use the newer QRegularExpression class (http://doc.qt.io/qt-5/qregularexpression.html), rather than QRegExp.

    Your example is indeed best handled via a numeric range validator, but there are plenty of other cases where a regular expression is suitable.

  • QML to Python

    Unsolved
    2
    0 Votes
    2 Posts
    2k Views
    SGaistS

    Hi and welcome to devnet,

    There's nothing to convert.

    main.py:

    #!/usr/bin/env python import sys from os.path import join from os.path import dirname from PyQt5.QtCore import QUrl from PyQt5.QtGui import QGuiApplication from PyQt5.QtQuick import QQuickView if __name__ == "__main__": app = QGuiApplication(sys.argv) url = QUrl(join(dirname(__file__), 'main.qml')) view = QQuickView() view.setSource(url) view.show() sys.exit(app.exec_())

    main.qml:

    import QtQuick 2.0 Rectangle { width: 360 height: 360 Text { text: qsTr("Hello Qt") anchors.centerIn: parent } MouseArea { anchors.fill: parent onClicked: { Qt.quit() } } }