Issue
I want to add a button during a event, but for some reason it doesn't work.
If i run this code, the TempFunc function will run during creation and a button will be created.
from PySide.QtGui import *
from PySide.QtCore import *
import sys
import math
class Example(QWidget):
def __init__(self, val):
super(Example,self).__init__()
self.scrollAreaConstraint = QLabel()
self.scrollAreaConstraint.setFixedSize(QSize(400,400))
self.scroll = QScrollArea()
self.scroll.setWidget(self.scrollAreaConstraint)
self.scroll.setWidgetResizable(True)
layout = QVBoxLayout(self)
layout.addWidget(self.scroll)
self.CountSlider = QSlider()
self.CountSlider.setOrientation(Qt.Orientation(1))
layout.addWidget(self.CountSlider)
self.TempFunc() #THIS WILL CREATE THE BUTTON!!
def TempFunc(self):
print "SLIDER PRESSED!!! NOW I WILL ADD A BUTTON"
QPushButton(self.scrollAreaConstraint)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
window = Example(25)
window.setGeometry(500, 500, 500, 400)
window.show()
sys.exit(app.exec_())
However running this, pressing the slider will cause the same TempFunc function to run, but the button is not created.
from PySide.QtGui import *
from PySide.QtCore import *
import sys
import math
class Example(QWidget):
def __init__(self, val):
super(Example,self).__init__()
self.scrollAreaConstraint = QLabel()
self.scrollAreaConstraint.setFixedSize(QSize(400,400))
self.scroll = QScrollArea()
self.scroll.setWidget(self.scrollAreaConstraint)
self.scroll.setWidgetResizable(True)
layout = QVBoxLayout(self)
layout.addWidget(self.scroll)
self.CountSlider = QSlider()
self.CountSlider.setOrientation(Qt.Orientation(1))
layout.addWidget(self.CountSlider)
#self.TempFunc() #<----Disabled!!
self.CountSlider.sliderPressed.connect(self.TempFunc)
def TempFunc(self):
print "SLIDER PRESSED!!! NOW I WILL ADD A BUTTON"
QPushButton(self.scrollAreaConstraint)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
window = Example(25)
window.setGeometry(500, 500, 500, 400)
window.show()
sys.exit(app.exec_())
Why is the button not created when not being called directly from the "init"?
Solution
I eventually found that QT will set the .visible flag to false by default. So just setting it to true makes the buttons visible in both cases.
Still not sure how and why it works when calling it from the init function as they are set to visible(false) aswell.
Answered By - Malu05
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.