qpushbutton

PyQt: Add qpushbutton dynamically

 ̄綄美尐妖づ 提交于 2020-01-11 11:23:31
问题 I am trying to figure out how to create QPushButton by pressing another QPushbutton so that I can ultimately create buttons dynamically. It seems like the initial method for creating buttons doesn't work in a function. import sys from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget from PyQt5.QtWidgets import QPushButton from PyQt5.QtCore import QSize class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self

PyQt: Add qpushbutton dynamically

元气小坏坏 提交于 2020-01-11 11:23:14
问题 I am trying to figure out how to create QPushButton by pressing another QPushbutton so that I can ultimately create buttons dynamically. It seems like the initial method for creating buttons doesn't work in a function. import sys from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget from PyQt5.QtWidgets import QPushButton from PyQt5.QtCore import QSize class MainWindow(QMainWindow): def __init__(self): QMainWindow.__init__(self) self

Qt rightclick QPushButton

安稳与你 提交于 2020-01-09 10:45:54
问题 I'm using Qt Creator to create a gui for a mineseeper game. How can I know a QpushButton clicked with rightclick? for flag in the game. In other word, which signal used for rightclick? 回答1: Create your own button with filter at mousePressEvent slot. qrightclickbutton.h #ifndef QRIGHTCLICKBUTTON_H #define QRIGHTCLICKBUTTON_H #include <QPushButton> #include <QMouseEvent> class QRightClickButton : public QPushButton { Q_OBJECT public: explicit QRightClickButton(QWidget *parent = 0); private

Two colours text in QPushButton

限于喜欢 提交于 2019-12-29 08:37:04
问题 I need a QPushButton with two colors in the text. I found a solution with a html code in QTextDocument and it's working. But I need center align and the html code isn't working. QTextDocument Text; Text.setHtml("<p align=center><font>Button</font><br/><font color=yellow>1</font></p>"); QPixmap pixmap(Text.size().width(), Text.size().height()); pixmap.fill( Qt::transparent ); QPainter painter(&pixmap); Text.drawContents(&painter, pixmap.rect()); QIcon ButtonIcon(pixmap); ui->toolButton-

Adding image to QPushButton on Qt

℡╲_俬逩灬. 提交于 2019-12-25 05:24:15
问题 I'm fairly new to C++ in general, so I need a little help with Qt. I'm trying to add an image to a PushButton, and I keep having problems with it. Here is an example of what I have: #include <QtWidgets/QPushButton> QPushButton *button; button = new QPushButton(Example); button->setObjectName(QStringLiteral("button")); button->setGeometry(0,0,128,56); So I have a picture saved in /example/pics/example.png (example being the project name), and I would like to use it on the PushButton. I've been

PySide: base on the groupbox example of PySide-Example , issue An error native Qt signal is not callable [duplicate]

会有一股神秘感。 提交于 2019-12-25 04:54:25
问题 This question already has answers here : PySide : How to get the clicked QPushButton object in the QPushButton clicked slot? (4 answers) Closed 5 years ago . Base on the groupbox example of PySide-Example, I add a clicked slot to the pushButton , such as: def createPushButtonGroup(self): ... pushButton = QtGui.QPushButton("&Normal Button") pushButton.clicked(self.normalClick) ... def normalClick(self): print self.sender.pushButton.text() But it issues an error: TypeError: native Qt signal is

QPushButtons in a column of a treeview

五迷三道 提交于 2019-12-25 04:24:55
问题 I already have a tree model view that contains columns with a label, text edit, and a check button. What I am trying to add is a push button. Here is where I'm stuck: In the "flags" function which namespace will I use? In the "data" function what would be the role of the push button? (for example in the check button case I used the Qt::CheckStateRole ) In the "data" function (which returns a QVariant ) what should I return? The button created? I have looked at other answers regarding this

Qt disabling dynamic buttons

夙愿已清 提交于 2019-12-25 04:23:52
问题 I am trying to disable button previously chosen by user void pracownik2::on_pushButton_4_clicked(){ this->setWindowTitle("EKRAN"); QWidget *centralWidget = new QWidget; int licznik=1; QString licz; //QString kolumny = ui->lineEdit->text(); //QString wiersze = ui->lineEdit_2->text(); miejsca2 = ui->lineEdit_3->text().toInt(); //QPushButton *button[wiersze.toInt()][kolumny.toInt()]; QPushButton *button[3][6]; QGridLayout *controlsLayout = new QGridLayout; for(int i=0;i<3;i++) { for(int j=0;j<6

Qt - Get QPushButton icon name

大憨熊 提交于 2019-12-24 10:49:10
问题 I have a two state QPushButton. I want to associate an icon to each state. It is like Play|Pause buttons in music players. To do so, I would like to get the current icon name in order to know what the next icon to set will be. I could subclass QPushButton but is it worth it? 回答1: Use QPushButton::icon() and QIcon::name() to get the icon name. 回答2: Instead of setting an icon based on the QPushButton 's state, set one QIcon that has two states, Qt will select the correct icon if you use it with

How to auto change QPushButton width and QMenuBar corner widget width when change text of button?

天涯浪子 提交于 2019-12-24 07:09:57
问题 I set corner widget into QMenuBar that has two QPushButtons. But when I set long text by button's setText, button doesn't change it's weight, so, icon and part of text hiding. So, how to change button's width and width of corner widget when set text? 回答1: Call menuBar()->adjustSize(); after setting the text on the button. 回答2: I resolved it by setting the same corner widget into QMenuBar again after changing button text. 来源: https://stackoverflow.com/questions/15422439/how-to-auto-change