开发者

QPushbutton place image , 2 Labels on top of it in QT?

开发者 https://www.devze.com 2023-03-12 14:34 出处:网络
how to place a image , 2 lables on a QPushButton ? My requirement is i want to have one开发者_开发知识库 button in which a image should be placed on left hand side , text should be there just after t

how to place a image , 2 lables on a QPushButton ?

My requirement is i want to have one开发者_开发知识库 button in which a image should be placed on left hand side , text should be there just after the image and one more text at the end of the button ?

Currently i am using below code which allows me to place image on left hand side but text comes in middle and i am not able to set text at the end of my button.

b1->setStyleSheet(
                                "background-image: url(:/user.gif);"
                                "background-repeat:no-repeat;"
                                "background-attachment:fixed;"
                                "background-position:left top;"
                                "border-style: outset;"
                                "background-color : black;"
                                "border-width: 2px;"
                                "border-radius: 10px;"
                                "border-color: black;"
                                "font: bold 16px;"
                                "color: black;"
                                "min-width: 400px;"
                                "min-height: 0.75em;"
                                "margin: 0 1px 0 1px;"
                                "color:rgb(255,255,255);"
                                "padding: 6px;"
                                );


You can create a push button, make it have no icon or text, and then add a layout to it. You can add widgets to the layout however you desire. The only thing to be aware of is that the layout will expand to the outside dimensions of the button, so you need to be sure your margin on the layout accounts for the space that the button border uses to draw. This gets you something that looks like a push button, but with whatever other widgets you want on it.

Of course, if you are styling the button so much or using it dynamically, it would probably be easier to create your own subclass of QAbstractButton and use it.


Afaik, you can't place two labels on a regular QPushbutton. I also don't think this is achieveable with standard CSS when the text is in the same block. I'd say subclass QAbstractButton to have two labels.

0

精彩评论

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