Change color text QAction



  • hiii, please i have same QAction in my form and i want to change color text, I have not found how to do it.help Thank you in advance



  • You can use a QWidgetAction like

    QWidgetAction *newAct = new QWidgetAction(this);
    QLabel *label = new QLabel(tr("New"));
    label->setStyleSheet("color: red");
    newAct->setDefaultWidget(label);
    newAct->setShortcuts(QKeySequence::New);
    newAct->setStatusTip(tr("Create a new file"));
    connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
    
    ...
    ...
    menu->addAction(newAct );
    


  • I can not apply the style directly on QAction?because I work on an application already prepared and I not master code, voila les images de mon QAction
    http://server.mediazain.com/capture.png



  • there to there not a tag as for color in form file ??
    <property name="font">
    <font>
    <bold>true</bold>
    </font>
    </property>



  • QAction does not support styleSheet or Palette as its just a holder class that inherits QObject. Inorder to use stylesheets/color you need to use it a QWidgetAction incase of a QMenu. In the image link where do you use a QAction ?

    check

    1. Customizing QMenu
    2. Customizing QToolButton


  • I was able to apply style bold in text QAction in ui file

    <action name="actionBack">
    <property name="icon">
    <iconset resource="../sankore.qrc">
    <normaloff>:/images/toolbar/previousPageOn.png</normaloff>:/images/toolbar/previousPageOn.png</iconset>
    </property>
    <property name="text">
    <string>Précédent</string>
    </property>
    <property name="toolTip">
    <string>Précédent</string>
    </property>
    <property name="shortcut">
    <string>PgUp</string>
    </property>
    <property name="font">
    <font>
    <bold>true</bold>
    </font>
    </property>
    </action>

    there to there not a way to change the color of text? Thank you for your answer.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.