0

I want to keep track of the user modifying the company's forecast in my custom made app. I created it using qt designer and PyQt4, and I'm using QSpinBox for the quantities (easy way to control range of values and masking the fields to be number only). The problem I'm having is when I want to get the QSpinBox that triggered my function. At this moment it's being triggered using valueChanged.connect but could be using anything else. I can get the int in the spinbox but not the spinbox's name. Thanks beforehand for the help!

SOLUTION

The QSpinBox element

self.Item = QtGui.QSpinBox(self.centralwidget)  
self.Item.setObjectName(_fromUtf8("ItemName"))

Trigger

self.Item.valueChanged.connect(self.foo)

The function it calls

def foo(self,obj):  
    sender = MainWindow.sender()  
    print sender.objectName()

In this case "MainWindow" is my QtCore.QObject

1 Answers1

0

AS the question tagged C++. I am answering in both C++ and pyQt4. I never worked in pyQt4. So please excuse me for syntax.

In the "valueChanged" slot use QObject::sender() to get the spin box which triggered it.

And then call "objectName()".

QObject* obj = sender();
QString objName = obj->objectName();

May be in python:

 sender = QtCore.QObject.sender()
 str = sender.objectName()
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34