开发者

Qt - QPushButton margin of icon needs to stay the same

开发者 https://www.devze.com 2023-01-31 12:43 出处:网络
I create a set of buttons using the function below with text, buttonName, that can change in width.The icon that appears when I click one of the buttons then justfies itself based on the width of the

I create a set of buttons using the function below with text, buttonName, that can change in width. The icon that appears when I click one of the buttons then justfies itself based on the width of the text; how do I make the icon stay the same margin from the right of the button regardless of text? Don't say custom delegate, because I haven't been able to figure out how to implement that!

QPushButton开发者_StackOverflow中文版 *LayoutCreator::createButton(const QString &buttonName) {

   QIcon ico;
   ico.addPixmap(QPixmap(":images/images/on.png"), QIcon::Normal, QIcon::On);
   ico.addPixmap(QPixmap(":images/images/off.png"), QIcon::Normal, QIcon::Off);

   QPushButton* button = new QPushButton(buttonName);
   button->setStyleSheet("QPushButton { height: 70px; font-size: 20px; }");
   button->setIcon(ico);
   button->setLayoutDirection(Qt::RightToLeft);
   button->setIconSize(QSize(32,32));
   button->setCheckable(true);

   return button;

}


Try adding

text-align: right;

to your button style sheet.

0

精彩评论

暂无评论...
验证码 换一张
取 消