Results 1 to 14 of 14

Thread: [PyQT] QDataWidgetMapper and Custom Widget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2015
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: [PyQT] QDataWidgetMapper and Custom Widget

    I finally managed to make it working! Your code is exactly the same as I tried before my last post and I did not manage to make it working because of a recursivity problem (the sigDataChanged signal was directly emitted in the setColor method).

    I had to change a little bit the code :
    Qt Code:
    1. class ColorWidget(QWidget):
    2. sigDataChanged = pyqtSignal(str)
    3. def __init__(self, color=None):
    4. some python code here
    5. self.btnColor.clicked.connect(self.changeColor)
    6.  
    7. def changeColor(self):
    8. colorInit = QColor()
    9. colorInit.setNamedColor(self._color)
    10. color = QColorDialog.getColor(colorInit, self, "Select a color")
    11. if color.isValid():
    12. self.ldtColor.setText(color.name())
    13. self.setColor(color.name())
    14. self.sigDataChanged.emit(self._color)
    15.  
    16. def updateIcon(self):
    17. pixmap = QPixmap(24, 24)
    18. newcolor = QColor()
    19. newcolor.setNamedColor(self._color)
    20. pixmap.fill(newcolor)
    21. icon = QIcon(pixmap)
    22. self.btnColor.setIcon(icon)
    23.  
    24. def getColor(self):
    25. return self._color
    26.  
    27. def setColor(self, newColor):
    28. self._color = newColor
    29. self.ldtColor.setText(newColor)
    30. self.updateIcon()
    31.  
    32. color = pyqtProperty(str, fget=getColor, fset=setColor)
    To copy to clipboard, switch view to plain text mode 
    I just emit the sigDataChanged signal after the setColor method has been called. Finally, I update the model by connecting this signal to the submit slot of the QDataWidgetMapper in the appropriate PropertiesEditor class (as you mentionned).
    Qt Code:
    1. self.colorWidget.sigDataChanged.connect(self.dataMapper.submit)
    To copy to clipboard, switch view to plain text mode 

    Problem solved. I close the thread.

    Thank you very much anda_skoa for your time and help .

    Cheers,

    Vincent

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: [PyQT] QDataWidgetMapper and Custom Widget

    Quote Originally Posted by Vincent Le Saux View Post
    I finally managed to make it working! Your code is exactly the same as I tried before my last post and I did not manage to make it working because of a recursivity problem (the sigDataChanged signal was directly emitted in the setColor method).
    My guess would be that this is a problem caused by not checking for actual change.

    I do that in setColor(), so the signal is only emitted if the color actually changes.

    But maybe PyQt behaves differently in some other aspect.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2015
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    1

    Default Re: [PyQT] QDataWidgetMapper and Custom Widget

    You are definitely right! I just check for changes in the setColor method, and the recursivity problem disappears.

    PyQt and Qt behaves exactly the same way on this aspect.

    Once again, thank you!

    Cheers,

    Vincent

Similar Threads

  1. QDataWidgetMapper and custom widget - read value
    By Hostel in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2013, 12:07
  2. Using QDataWidgetMapper with custom types
    By Zanyinj in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2011, 09:42
  3. [PyQt] Creating custom widget
    By asik in forum Newbie
    Replies: 1
    Last Post: 2nd December 2010, 14:33
  4. Custom QLineEdit to store NULL with QDataWidgetMapper
    By certqt in forum Qt Programming
    Replies: 3
    Last Post: 9th November 2010, 13:15
  5. Custom Widgets to PyQt
    By prashant in forum Qt Programming
    Replies: 0
    Last Post: 24th September 2009, 15:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.