#include <QApplication>#include <QtWidgets>int main(int argc, char *argv[]){ QApplication a(argc, argv); QWidget mywindow; QPushButton *btn1 = new QPushButton("1"); QPushButton *btn2 = new QPushButton("2"); QPushButton *btn3 = new QPushButton("3"); QPushButton *btn4 = new QPushButton("4"); QGridLayout *mylayout = new QGridLayout; mylayout->addWidget(btn1,0,0); mylayout->addWidget(btn2,0,1); mylayout->addWidget(btn3,1,0); mylayout->addWidget(btn4,1,1); mywindow.setLayout(mylayout); mywindow.show(); return a.exec();}
btn1->setSizePolicy(QSizePolicy::Preferred,QSizePolicy::Expanding);
C++ (Qt) QFont fontForButton; fontForButton.setPixelSize(300); QPushButton* testButton = new QPushButton("1"); testButton->setFont(fontForButton);
C++ (Qt) QPushButton* testButton = new QPushButton("1"); app.setStyleSheet("QPushButton { font: bold 400px;}"); testButton->show();
C++ (Qt)#include <QtCore>#include <QtGui> class MyPushButton : public QPushButton{ Q_OBJECTpublic: QFont font; MyPushButton(QPushButton* parent = 0) : QPushButton(parent) { setFont(font); setText("1"); } void resizeEvent(QResizeEvent *event){ font.setPixelSize(this->size().height() / 2); setFont(font); }}; int main(int argc, char** argv){ QApplication a(argc, argv); MyPushButton* testButton = new MyPushButton; testButton->show(); return a.exec();}
MyPushButton* testButton = new MyPushButton ([b]"Текст"[/b]);
MyPushButton( const QString & text, QWidget * parent = 0 )
QPushButton ( const QString & text, QWidget * parent = 0 )