ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
4

How to change Python Qt binding?

asked 2012-09-13 11:48:42 -0500

130s gravatar image

updated 2014-01-28 17:13:39 -0500

ngrennan gravatar image

In rqt's plugin tutorial in python, using qt_binding_helper is recommended/required for making plugin developers not to care which python - qt binding to use (namely either PyQt or PySide). But looks like qt_binding_helper internally uses PyQt by default. How can I change to PySide?

I tried following and still didn't work as I kind of expected.

from python_qt_binding.QtBindingHelper import select_qt_binding
:
class RealityWidget(QWidget):
    def __init__(self, context, node=None):        
        :
        select_qt_binding('pyside') # P.S.2
        loadUi(ui_file, self)

P.S.1 The reason I want to use PySide is first of all I like to avoid GPL that PyQt requires (as mentioned in python_qt_binding's wiki as well). Another trigger is that my code experiences this problem where using PyQt yields runtime error while PySide doesn't. This doesn't mean I have to use PySide but just want to avoid any possible unknown issues.

P.S.2 select_qt_binding


Update 9/17/12) As far as I searched my file system, no module uses python_qt_binding.QtBindingHelper.select_qt_binding.

__init__.py in rviz suggests that:

# Can use the following setattr() call to force one binding or the other.
# setattr(sys, 'SELECT_QT_BINDING', 'pyside')

But tyring to use like this it only fails to show still pyqt is in use:

import os
import sys
import rospy
import rosnode
setattr(sys, 'SELECT_QT_BINDING', 'pyside')        
from qt_gui.qt_binding_helper import loadUi
from python_qt_binding.QtBindingHelper import select_qt_binding, QT_BINDING 
from QtGui import QWidget, QTreeWidgetItem

class RealityWidget(QWidget):
    def __init__(self, context, node=None):
        select_qt_binding('pyside')
        print ('QT_BINDING=' + QT_BINDING) # this prints "pyqt"
        :
        ui_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'reality.ui')
        loadUi(ui_file, self)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2012-10-19 04:37:41 -0500

Dorian Scholz gravatar image

Using setattr(sys, 'SELECT_QT_BINDING', 'pyside') works, if it is executed before the first import of python_qt_binding. But if your code is running as a rqt plugin, rqt has already imported python_qt_binding, so your plugin cannot change the binding anymore.

To run rqt_gui (and therefore your plugin) with a specific binding use the command line option '--qt-binding' or '-b':

rosrun rqt_gui rqt_gui --qt-binding=pyside

For more command line options see rosrun rqt_gui rqt_gui -h.

rqt will also choose PySide, if PyQt is not installed on the system.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2012-09-13 11:48:42 -0500

Seen: 2,239 times

Last updated: Oct 21 '12