qpushbutton

function call through signal changes default keyed arguments to 'False'. Why?

≯℡__Kan透↙ 提交于 2021-02-16 20:21:06
问题 When calling a function via a signal connection as in mybutton.clicked.connect(myfunction) the function is called with all its arguments set to False. Even though default arguments have been set. Is this the expected behavior? The code below shows a simple example. For my particular case having all arguments set to False is not a big issue as I can simply catch it with an if statement. However I feel that knowledge on why it is implemented this way may be helpful for further projects. This

PyQt5: How to Re-Dock back a floated QDockWidget via a QPushButton?

此生再无相见时 提交于 2021-02-11 14:10:51
问题 I which to bring back to initial state an Undocked or floated QDockWidget with a QPushButton. from PyQt5 import QtCore, QtGui, QtWidgets class Mainwindow(object): def setupUi(self, window): window.setObjectName("window") window.resize(309, 148) self.centralwidget = QtWidgets.QWidget(window) self.centralwidget.setObjectName("centralwidget") self.Undock_btn = QtWidgets.QPushButton(self.centralwidget) self.Undock_btn.setGeometry(QtCore.QRect(4, 4, 100, 22)) self.Undock_btn.setStyleSheet(

How to make height of a QPushButton automatically fit the text?

白昼怎懂夜的黑 提交于 2021-02-10 14:21:52
问题 I have a QPushButton QPushButton *btn = new QPushButton(); btn->setText("Push \n Button"); The result is: I have tried btn->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred) with Qt Designer but it does not help. How can do so that the height of the button is automatically adjusted to fit with the content when I call setText ? 回答1: You can set the vertical size policy to an option that allows the widget to grow, the default option for vertical size policy of QPushButton is fixed,

PyQt5 from QLineEdit to variable [duplicate]

笑着哭i 提交于 2021-02-08 10:24:30
问题 This question already has answers here : How to get text in QlineEdit when QpushButton is pressed in a string? (3 answers) Closed 2 years ago . I have created a simple PyQt5 User Interface that looks like this: import sys from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QLineEdit class App(QWidget): def __init__(self): super().__init__() self.title = 'Test' self.left = 10 self.top = 10 self.width = 400 self.height = 500 self.initUI() def initUI(self): self.setWindowTitle(self

PyQt5 from QLineEdit to variable [duplicate]

泄露秘密 提交于 2021-02-08 10:23:18
问题 This question already has answers here : How to get text in QlineEdit when QpushButton is pressed in a string? (3 answers) Closed 2 years ago . I have created a simple PyQt5 User Interface that looks like this: import sys from PyQt5.QtWidgets import QApplication, QPushButton, QWidget, QLineEdit class App(QWidget): def __init__(self): super().__init__() self.title = 'Test' self.left = 10 self.top = 10 self.width = 400 self.height = 500 self.initUI() def initUI(self): self.setWindowTitle(self

PyQt5: Draw a line by clicking QPushButton

风流意气都作罢 提交于 2021-02-08 09:37:05
问题 I am trying to make it such that when I click a QPushButton a line is drawn. However the code I have right now makes the line at the beginning when the code is initiated and not after . The QPushButton doesn't seem to do any drawing. I also don't quite understand why when drawing you need an 'event' argument in the function. import sys from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QMainWindow, QGridLayout,QPushButton, QApplication, QWidget from PyQt5.QtCore import QSize,

connect a function when menu title is clicked

纵然是瞬间 提交于 2021-02-05 06:58:25
问题 I am trying to find open ports and add them to my menu. Right now, what I succeed having an action to my menu (like, "find ports"), and only if it's clicked - it will connect to my function that gets all free ports. Unfortunately, that's not what I am looking for. I want to click on the menu title , and get all port in my menu. Below is the code I have: This is the GUI part: from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow

PyQt5: QPushButton double click?

╄→尐↘猪︶ㄣ 提交于 2021-02-04 21:22:14
问题 I can't find a good answer for this: is there a way for double click to execute a certain function, and single click one other function?? For example: def func1(self): print('First function') def func2(self): print('Second function') self.ui.button.clicked.connect(self.func1) self.ui.button.doubleClicked.connect(self.func2) I've seen double clicking is possible for the QTreeview but not a QPushButton . Thanks! 回答1: You can add the functionality easily yourself by extending QPushButton class:

How to display a list of QPushButton?

北城余情 提交于 2021-02-04 21:08:04
问题 I am a qt noob and I am trying to build an application that needs to display the following: a list of e-mail (which I am displaying in column 1 of a grid layout with a QListWidget1 left list) a list of passwords (which I display in column 2 of grid layout in a QListWidget2 middle list) Now, I would like to display a list of button (1 for every element of the list) which is supposed to copy the password in the QListWidget2. Should I just loop in column 3 and add a push button for every row? Or

Qt - how to save my QTableView as a Excel File?

℡╲_俬逩灬. 提交于 2021-02-04 15:32:09
问题 Can anyone plz help me, how to save my QtableView as a Excel File. I have a QTableView and a QPushButton (Save Button). If i enter the values in my QtableView and if i click the Save Buttton the QTableView items should be saved as Excel File. Plz Help me. Thanks.. 回答1: Have a look at this thread My-approach-to-export-QTableView-data-to-a-Microsoft-Excel-file. I got this link by asking Google for: QTableView save. For the solution there you need a Qt with ODBC enabled which is not the default.