Questions tagged [qpushbutton]

QPushButton is a Qt library class that represents ordinary push buttons, and gives the API to manipulate them.

QPushButton offers a set of functions to manipulate the button's appearance and behavior.

A minimalistic QPushButton example will look like this:

#include <QtGui>
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a( argc, argv );
    QPushButton * myButton = new QPushButton("Hello, World!");
    myButton->show();
    return a.exec();
}

One of QPushButton's most notable properties is Checkable, which can be accessed via setCheckable( bool ) function. If this option is set to true, the QPushButton becomes a toggle button which can be toggles on and off, and will stay in the corresponding state until toggled again.

The official Qt documentation can be found here for Qt 4.8 and here for Qt 5.

631 questions
43
votes
4 answers

How to make a QPushButton pressable for enter key?

I want to make my app laptop friendly. I can tab to everywhere, but if I tab to a QPushButton I can't press it with Enter, only with space. What's the problem? How to make it pressable for Enter?
totymedli
  • 29,531
  • 22
  • 131
  • 165
42
votes
2 answers

Difference between QPushButton and QToolButton

I'm new to Qt and the difference between QPushButton and QToolButton is not so clear to me. I know that a QToolButton is usually used in a QToolBar and it usually shows only an icon, without text, but I don't quite understand the main difference…
KelvinS
  • 2,870
  • 8
  • 34
  • 67
27
votes
2 answers

How to override just one property:value pair in Qt StyleSheet

I am writing newbie Qt5 code on OSX Mavericks and would like to override just one property:value pair of the StyleSheet for a given widget. If I run the following self-contained demonstration code: #include #include…
lcikgl
  • 759
  • 1
  • 8
  • 20
24
votes
7 answers

Qt5 - setting background color to QPushButton and QCheckBox

I'm trying to change the background color of a QAbstractButton (either a QPushButton or QCheckBox) in Qt5 and having zero luck. This does nothing: pButton->setAutoFillBackground(true); QPalette palette =…
Betty Crokker
  • 3,001
  • 6
  • 34
  • 68
22
votes
9 answers

How do I prevent the enter key from closing my QDialog (Qt 4.8.1)

I have a QDialog with a QDialogButtonBox. The OK and Cancel buttons are active. Occasionally I disable or hide the OK button based on the state of my dialog. It seems, no matter what I do, the Enter key always activates the OK button. I really DON'T…
cppguy
  • 3,611
  • 2
  • 21
  • 36
22
votes
2 answers

How to set animated icon to QPushButton in Qt5?

QPushButton can have icon, but I need to set animated icon to it. How to do this? I created new class implemented from QPushButton but how to replace icon from QIcon to QMovie?
Robotex
  • 1,064
  • 6
  • 17
  • 41
13
votes
4 answers

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

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 …
tao4yu
  • 316
  • 1
  • 5
  • 16
12
votes
4 answers

Qt rightclick QPushButton

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?
Khosi
  • 183
  • 1
  • 3
  • 9
12
votes
3 answers

How to set the font size of the label on pushbutton in Qt?

I am using this code to set a label on the pushbutton with size of 16 ui->pushButton->setText(tr("Tank 1 \n %1%2C").arg(szTemp).arg(degree)); but I am getting the output as Tank 1 005c written on…
Amar
  • 379
  • 2
  • 5
  • 18
11
votes
4 answers

How do I assign a shortcut to a QPushButton?

The documentation on assigning a shortcut to a QPushButton is as follows: A shortcut key can be specified by preceding the preferred character with an ampersand in the text. For example: QPushButton *button = new QPushButton("&Download", this); In…
Kvass
  • 8,294
  • 12
  • 65
  • 108
10
votes
1 answer

Qt 5 assign slot with parameters to a QPushButton

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…
Bankin
  • 777
  • 1
  • 16
  • 31
9
votes
2 answers

Add widgets into a QTabWidget

Can I add some widgets like QLabel and QPushButton into a QTabWidget? Actually, I want to do something like this: I'm using C++ and Qt. Thanks
KelvinS
  • 2,870
  • 8
  • 34
  • 67
9
votes
2 answers

Flat QPushButton, background-color doesn't work

I created QPushButton in Qt Designer with this stylesheet: QPushButton#pushButton { background-color: #ffffff; } QPushButton#pushButton:disabled { background-color: yellow; } QPushButton#pushButton:pressed { background-color: orange;…
tomsk
  • 967
  • 2
  • 13
  • 29
9
votes
1 answer

How can we delete icon from QPushButton?

After begining the program I set icons on all pushbuttons. Code is like this: QImage img; img.load(pictureName); ui->pushButton_1->setIcon(QPixmap::fromImage(img)); ui->pushButton_1->setIconSize(img.size()); But after some actions I need delete…
СhiliРepper
  • 125
  • 1
  • 6
8
votes
2 answers

QPushButton has duplicated text after Qt upgrade

I have an Android application written in C++ using Qt Creator. After the Qt version upgrade (from 4.8 to 5.4) I observed a strange behaviour: all QPushButton got duplicated text label, one is at the correct position and the other is shifted a bit…
Steve M. Bay
  • 313
  • 1
  • 3
  • 15
1
2 3
41 42