Qt World Summit: Submit your Presentation

QToolButton Icon position

  • Is it possible to manipulate the position of the Icon inside a QToolButton?
    In my case, the icon is to near the top border, I want to set a top margin to the icon.
    But the setStyleSheet only set the margin to the button itself.

    button->setStyleSheet("QToolButton { margin-top: 10px; } ");



  • Lifetime Qt Champion


    What version of Qt ?
    On what OS ?
    Can you show what you get ?
    Can you show what you would like to achieve ?

  • @pixbyte

    AFAIK you cant use Stylesheet on QIcons directly to set a margin, because a QIcon is not a QWidget.

    Write a custom Button and define a custom icon position / area inside your Button?!

  • @pixbyte
    you should use even stylesheet for all this

    button->setStyleSheet("QToolButton {
    background-image: url(:/path/to/image.jpg);
    margin-top: 10px;
    } ");

    you can play with background-image or with image
    Not tested but should work

Log in to reply