class MyPushButton: public QPushButton{ public: MyPushButton(const QIcon &icon, const QString &text, QWidget *parent = 0) :QPushButton(icon, text, parent) { QLayout *l = layout(); qDebug("%d\n", l); // 0 }};
QPushButton *myButton = new QPushButton(this);myButton->setGeometry(10,10,400,100);QLabel *myIcon = new QLabel(myButton);myIcon->setAttribute(Qt::WA_TransparentForMouseEvents);myIcon->setGeometry(0,0,100,100);myIcon->setPixmap(QPixmap("C:/pix.png"));QLabel *myText = new QLabel(myButton);myText->setGeometry(100,0,300,100);myText->setAttribute(Qt::WA_TransparentForMouseEvents);myText->setText("SomeText");
iconRect = QRect(textRect.x(), textRect.y() + (textRect.height() - labelHeight) / 2, pixmap.width(), pixmap.height());
Qt::Alignment labelAlign = Qt::AlignLeft;if(labelAlign == Qt::AlignLeft) iconRect = QRect(textRect.x(), textRect.y() + (textRect.height() - labelHeight) / 2, pixmap.width(), pixmap.height());else if(labelAlign == Qt::AlignRight) iconRect = QRect(textRect.x() + (textRect.width() - labelWidth), textRect.y() + (textRect.height() - labelHeight) / 2, pixmap.width(), pixmap.height());else //// Qt::AlignHCenter iconRect = QRect(textRect.x() + (textRect.width() - labelWidth) / 2, textRect.y() + (textRect.height() - labelHeight) / 2, pixmap.width(), pixmap.height());