Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Self colouring QPushButton not working inside table
Forum Updated to NodeBB v4.3 + New Features

Self colouring QPushButton not working inside table

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    frueter
    wrote on last edited by
    #1

    Hi everyone,

    I've got this snippet of code which creates a self colouring QPushButton (push button to open a colour choser, then use the chosen colour to set the button's bg colour. This is it and it works just fine:
    @import sys
    import PySide.QtCore as QtCore
    import PySide.QtGui as QtGui

    class ColourButton( QtGui.QPushButton ):
    def init( self, *args, **kwargs ):
    '''A self colouring button'''
    super( ColourButton, self ).init( *args, **kwargs)

    def chooseColour( self ):
        colour = QtGui.QColorDialog().getColor()
        self.setStyleSheet( u'background-color:%s' % colour.name() )
    

    if name == "main":
    app = QtGui.QApplication( sys.argv )
    btn = ColourButton( '...' )
    btn.clicked.connect( btn.chooseColour )
    btn.setFlat( True )
    btn.show()
    sys.exit( app.exec_() )
    @

    Now I'm trying to populate a cell table with this button:
    @import sys
    import PySide.QtCore as QtCore
    import PySide.QtGui as QtGui

    class ColourButton( QtGui.QPushButton ):
    def init( self, *args, **kwargs ):
    '''A self colouring button'''
    super( ColourButton, self ).init( *args, **kwargs)

    def chooseColour( self ):
        colour = QtGui.QColorDialog().getColor()
        self.setStyleSheet( u'background-color:%s' % colour.name() )
    

    class TestTable( QtGui.QWidget ):
    def init( self, parent=None ):
    QtGui.QWidget.init( self, parent )
    self.setLayout( QtGui.QVBoxLayout() )
    self.resize( 500, 300 )
    self.myTable = QtGui.QTableWidget()
    self.myTable.header = ['Name', 'Colour' ]
    self.myTable.size = [ 75, 375, 85, 600 ]
    self.myTable.setColumnCount( len(self.myTable.header) )
    self.myTable.setRowCount( 5 )

        for i in range( 0, self.myTable.rowCount() ):           
            # SET COLOURBUTTON WIDGETS
            colBtn = ColourButton( '...' )
            colBtn.clicked.connect( colBtn.chooseColour )
            colBtn.setFlat( True ) # THIS SEEMS TO PREVENT ColourButton.chooseColour() FROM DOING IT'S JOB
            self.myTable.setCellWidget( i,1,colBtn )
    
            self.layout().addWidget( self.myTable )
    

    if name == "main":
    app = QtGui.QApplication( sys.argv )
    tableView = TestTable()
    tableView.show()
    sys.exit( app.exec_() )
    @

    For some reason, the button won't colour itself any longer when called from inside the table. And even stranger (to me at least) is that if I comment out the line that sets the button's style to "flat" (line 31: colBtn.setFlat( True ) ), it does work again.

    Am I doing something wrong or is this a bug? I would definitely prefer using a flat button.

    Cheers,
    frank

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Marcos Modenesi
      wrote on last edited by
      #2

      Wow, I posted the same question today. Any succes?

      http://qt-project.org/forums/viewthread/28360/

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved