Important: Please read the Qt Code of Conduct -

Changing stylesheet or tooltip in one go

  • I have made one large project using Qt designer which has .ui, .cpp, .h files.
    Now I want to add colors and tool-tip to pushbuttons of all .ui files in one go or some easy way, because it WOULD BE VERY DIFFICULT TO GO THROUGH ALL .ui files and change color of each pushbuttons.
    Is there anyway I can do this?
    If you are not sure you can share your ideas.

  • Lifetime Qt Champion

    stylesheets are cascading. Do not assign to each button.!
    so if you assign stylesheet to mainwindow, then
    all buttons owned by mainwindow or children with buttons would all be affected.
    If you have parentless dialog, its not affected. ( as not a child)
    But you can set same stylesheet on such windows.

    Regarding tooltip. how would that be possible, you would need a list that says
    thisbutton, that text
    so how can a program know what text to use ?

  • Moderators


    QPushButton {
        color: red;
        background: white;
       border: 1px solid grey;
        qproperty-toolTip: "Same ToolTip for all buttons";
    /* define special buttons by setting the object-name */
    QPushButton#SpecialButton {
        qproperty-toolTip: "Special ToolTip";

    if you set the stylesheet on the QApplication instance, all windows (even parentless ones) will receive it.

    But note that you wont be able to translate the tooltip text, when it's set via stylesheet.

  • Lifetime Qt Champion

    let us know
    if you find a good way of setting different
    tooltips on all the buttons. :)

Log in to reply