Damn.. thanks Justin! That work splendid

b = QtGui.QToolButton()
l = QtGui.QVBoxLayout(b)
b.setFixedSize(50, 50)
b.setIconSize(QtCore.QSize(50,50))
standardFont = QtGui.QFont("Arial", 10, QtGui.QFont.Bold)
standardFont.setCapitalization(QtGui.QFont.AllUppercase)
text = QtGui.QLabel("Text")
b.setIcon(QtGui.QIcon(os.path.join(ICON_DIR, 'csLighting_ftrackTime.png')))
l.setContentsMargins(0,0,0,0)
l.addStretch()
l.addWidget(text, 0, QtCore.Qt.AlignCenter)
text.setFont(standardFont)
b.show()


On Thursday, March 17, 2016 at 1:10:50 AM UTC, Justin Israel wrote:
>
> That's actually almost the exact same code in the example that I gave, 
> except instead of adding both the image and the text as individual objects 
> to the layout, you just set the picture on the button, and only add the 
> text to the layout. The result is that the image is drawn, centered in the 
> button, and the text is laid out over it in the center.
>
> Justin
>
> On Wed, Mar 16, 2016 at 11:03 PM Arvid Schneider <[email protected] 
> <javascript:>> wrote:
>
>> HI Justin, 
>> I ve tried your example. I didnt mean with "on top" that the text should 
>> come first then the icon in the vertical layout. 
>> If I have square btn, I want the text to float on top of the icon. 
>> Check the attachment
>>
>>
>>
>> On Tuesday, March 15, 2016 at 10:13:17 PM UTC, Arvid Schneider wrote:
>>>
>>> Thanks you two! Always a life saver!
>>> I will try it with custom layouts, and keep you posted. 
>>>
>>>
>>> On Tue, Mar 15, 2016 at 9:47 PM Marcus Ottosson <[email protected] 
>>> <javascript:>> wrote:
>>>
>>>> Yeah, as soon as you apply even an empty stylesheet, most of the native 
>>>> look is gone. Tis pity. :(
>>>>
>>>> A custom layout, or custom toolbutton is what I would do. Possibly 
>>>> reshuffle the widgets so one ends up ontop of the other, they are likely 
>>>> in 
>>>> a regular QVBoxLayout internally.
>>>>
>>>> On 15 March 2016 at 21:39, Justin Israel <[email protected] 
>>>> <javascript:>> wrote:
>>>>
>>>>> Hey Arvid,
>>>>>
>>>>> You could do it with StyleSheets but the pain in the butt is that once 
>>>>> you start defining some of the button style stuff, you have to define all 
>>>>> of the look. i.e. the gradients and borders, etc.. 
>>>>>
>>>>> Another way that you could solve this is to just do a custom layout 
>>>>> inside of the button:
>>>>>
>>>>> b = QtGui.QToolButton()
>>>>> l = QtGui.QVBoxLayout(b)
>>>>> text = QtGui.QLabel("Text")
>>>>> pic = QtGui.QLabel()
>>>>> pic.setPixmap('path_to_icon.png')
>>>>> pic.setScaledContents(True)
>>>>> l.addWidget(text, 0, QtCore.Qt.AlignCenter)
>>>>> l.addWidget(pic, 0, QtCore.Qt.AlignCenter)
>>>>> b.setMinimumSize(100, 60)
>>>>>
>>>>>
>>>>> --Justin
>>>>>
>>>>>
>>>>> On Wed, Mar 16, 2016 at 8:41 AM Arvid Schneider <[email protected] 
>>>>> <javascript:>> wrote:
>>>>>
>>>>>> Hi there, 
>>>>>> been searching the forums quite a bit..but couldnt find something 
>>>>>> reasonable. 
>>>>>> I have a QToolButton and an icon. I dont want to bake the text into 
>>>>>> the icon image, I d rather have a text using btn.setText("Text").
>>>>>> The problem the text is set right underneath the icon which I dont 
>>>>>> want in my case. 
>>>>>> It should be on top of the icon. Is there any way to do that? 
>>>>>> I guess with a custom QToolButton..could someone help me out there?
>>>>>>
>>>>>>
>>>>>> btn = QtGui.QToolButton()
>>>>>> btn.setText("Text")
>>>>>> icon = QtGui.QIcon()
>>>>>> icon.addPixmap(os.path.join('path_to_icon.png', QtGui.QIcon.Normal, 
>>>>>> QtGui.QIcon.On)
>>>>>> btn.setIcon(icon)
>>>>>>
>>>>>> ideally:
>>>>>> icon.setToolButtonStyle(QtCore.Qt.ToolButtonText*OnTop*Icon
>>>>>>
>>>>>>
>>>>>>
>>>>>> Is there a way to offset the text using style sheet?
>>>>>> Any help is appreciated
>>>>>>
>>>>>> -- 
>>>>>> You received this message because you are subscribed to the Google 
>>>>>> Groups "Python Programming for Autodesk Maya" group.
>>>>>> To unsubscribe from this group and stop receiving emails from it, 
>>>>>> send an email to [email protected] 
>>>>>> <javascript:>.
>>>>>> To view this discussion on the web visit 
>>>>>> https://groups.google.com/d/msgid/python_inside_maya/1b3c3979-741f-476d-99ea-da96b656819b%40googlegroups.com
>>>>>>  
>>>>>> <https://groups.google.com/d/msgid/python_inside_maya/1b3c3979-741f-476d-99ea-da96b656819b%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>> .
>>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>>
>>>>> -- 
>>>>> You received this message because you are subscribed to the Google 
>>>>> Groups "Python Programming for Autodesk Maya" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>>> an email to [email protected] 
>>>>> <javascript:>.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2SdNnKLwU1oJax%3DADFZu%3Dimxx2CNraJjJsdXGvmqA90g%40mail.gmail.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2SdNnKLwU1oJax%3DADFZu%3Dimxx2CNraJjJsdXGvmqA90g%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>>
>>>>
>>>> -- 
>>>> *Marcus Ottosson*
>>>> [email protected] <javascript:>
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Python Programming for Autodesk Maya" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to [email protected] 
>>>> <javascript:>.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAqE_Q3wXxwKWXg4-PD6y-cwNySg6Q45Tva5OUypTPEKw%40mail.gmail.com
>>>>  
>>>> <https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAqE_Q3wXxwKWXg4-PD6y-cwNySg6Q45Tva5OUypTPEKw%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Python Programming for Autodesk Maya" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/python_inside_maya/aed9e52b-57e5-403e-a7c1-f27890ed91af%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/python_inside_maya/aed9e52b-57e5-403e-a7c1-f27890ed91af%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/c8efb5f9-859e-4f38-adb9-643dc3144a9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to