qpushbutton

qt how to know that a pushbutton is clicked?

让人想犯罪 __ 提交于 2019-12-04 16:36:23
I'm trying to do a program which makes some operations with sounds. My question is that I have 3 Play pushbutton and 3 label. I want that whichever I click on the Play button, the sound whose name is in the label that is near the pushbutton should play. I have a play slot without any parameter. So, how can I connect to every play button with every label respectively? Actually, I can write 3 different play function, but since I have some other functions, it will be too long and confusing. Also, I need 3 play button because I want to play 3 sounds simultaneously. For example by connecting the

Qt 5 assign slot with parameters to a QPushButton

。_饼干妹妹 提交于 2019-12-04 09:31:21
问题 I have a Qt application on C++ and I want to assign a slot to a QPushButton. But I want to pass some arguments because I have more than one QPushButton doing similar thing so I want one function but with a parameter in it but Qt keeps saying me that there is no slot like this. Can someone tell me why and how should I do it? Thank you in advance In the .h file I have: (it was private in the beginning but I changed it in searching of the problem) public slots: void handleButton(int row, int col

How to set push-button to keyboard interrupt in PyQt

谁说胖子不能爱 提交于 2019-12-04 06:26:16
问题 While running program through the terminal we can stop the program by pressing 'Ctrl+c' and it will show the message as 'KeyboardInterrupt' . So, is there any way to do the sane thing by clicking the push-button in PyQt. 回答1: If your program is running a loop, you can call processEvents periodically to allow the gui time to update (which should allow you to click a button to close the application): count = 0 while True: count += 1 if not count % 50: QtGui.qApp.processEvents() # do stuff...

Set position (to right) of Qt QPushButton popup menu

倖福魔咒の 提交于 2019-12-03 16:14:33
I am writing a popup menu for a Qt push button widget. Whenever the push button is clicked, a menu pops up (below the push button). The popup menu is left-sided below by default. Are there any ways to make the popup menu to pop up on the right side below the push button? There is no set position function, so I wonder if there is some sophisticated way of doing it? Here is some code (for popup menu): QMenu *menuMode = new QMenu(this); min = menu ->addAction("In"); mout = menu ->addAction("out"); ui->pushButtonMode->setMenu(menuMode); //I am writing in MainWindow, that's there is ui This can be

PySide : How to get the clicked QPushButton object in the QPushButton clicked slot?

陌路散爱 提交于 2019-12-03 15:48:52
I am new to PySide. I want to get the QPushButton obj (such as use it to get its text) in its clicked slot. button = QtGui.QPushButton("start go") button.clicked.connect(self.buttonClick) def buttonClick(self): ... # How can I get the button object? # print button.text() how to get the text : 'start go' ? Thanks! qurban Here is what I did to solve the problem: button = QtGui.QPushButton("start go") button.clicked.connect(lambda: self.buttonClick(button)) def buttonClick(self, button): print button.text() You can just use self.sender() to determine the object that initiated the signal. In your

Qt 5 assign slot with parameters to a QPushButton

一个人想着一个人 提交于 2019-12-03 03:09:32
I have a Qt application on C++ and I want to assign a slot to a QPushButton. But I want to pass some arguments because I have more than one QPushButton doing similar thing so I want one function but with a parameter in it but Qt keeps saying me that there is no slot like this. Can someone tell me why and how should I do it? Thank you in advance In the .h file I have: (it was private in the beginning but I changed it in searching of the problem) public slots: void handleButton(int row, int col); Then in the .cpp: void fieldWindow::handleButton(int row, int col){ cout << row << " " << col <<

Change icon on state change using Qt stylesheet

╄→尐↘猪︶ㄣ 提交于 2019-12-02 12:22:49
问题 I'm trying to support theming for my application, and I'm coming across a problem where I have to change icons based on the state of the QPushButton (default, hover, pressed, etc.). Here is what I use to set the icon for a QPushButton: QPushButton#playButton { qproperty-icon: url(":/light/icons/play_light.png"); } Because the hover state uses a background that requires an icon from my dark theme, I tried to change it to the other using this: QPushButton#playButton:hover { qproperty-icon: url(

How to create a button for each element in a list and put it in a scroll-area?

点点圈 提交于 2019-12-02 09:26:08
I have a list which gets one element each time user opens a file. I need to create a button with the file's name (element from the list), each time this file is appended to a list, and put this button into a scroll-area. The problem is that I always have only one button, that just changes its name: filenames = [] def addfiles(): fileName = QtGui.QFileDialog.getOpenFileName() fileDirectory = unicode(fileName) global filenames filenames.append(fileDirectory) button = QtGui.QPushButton(os.path.basename(fileDirectory)) window.scrollArea.setWidget(button) I know that the problem is that I add the

PyQt5 button lambda variable becomes boolean [duplicate]

六月ゝ 毕业季﹏ 提交于 2019-12-02 07:48:26
This question already has an answer here: Capture variable from for-loop for using later in QPushButton [duplicate] 1 answer When I run the code below, it shows the below. Why isn't x 'x' but becomes a boolean? This happens only to the first argument passed into the function called with lambda. false y /home/me/model/some_file from PyQt5.QtWidgets import QPushButton modelpath = '/home/me/model' filelist = os.listdir(modelpath) x = 'x' y = 'y' def HelloWidget(QWidget): def __init__(self): for file in filelist: button = QPushButton(file) button.clicked.connect(lambda x=x,y=y,file=file: self

Change icon on state change using Qt stylesheet

纵饮孤独 提交于 2019-12-02 04:14:11
I'm trying to support theming for my application, and I'm coming across a problem where I have to change icons based on the state of the QPushButton (default, hover, pressed, etc.). Here is what I use to set the icon for a QPushButton: QPushButton#playButton { qproperty-icon: url(":/light/icons/play_light.png"); } Because the hover state uses a background that requires an icon from my dark theme, I tried to change it to the other using this: QPushButton#playButton:hover { qproperty-icon: url(":/dark/icons/play_dark.png"); } When I do this, the play_light.png displays as it should, but it doesn