Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How do I change the style of checkboxes for checkable QActions in a QMenu?
Forum Updated to NodeBB v4.3 + New Features

How do I change the style of checkboxes for checkable QActions in a QMenu?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 4.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qtim
    wrote on last edited by Qtim
    #1

    How do I change the style of checkboxes for checkable QActions in a QMenu?

    My menu works as expected but the checks are checkmarks with no boxes. I want to see empty box and checked box.

    My menu has this:
    alt text

    But I want this:
    alt text

    QMenu* mySubmenu = addMenu(tr("MySubmenu"));
    QAction *pAction;
     
    pAction = new QAction("Option 1");
    pAction->setCheckable(true);
    pAction->setChecked(isChecked());
    connect(pAction, &QAction::triggered, this, [=](bool checked) { onSubmenuClick(); } );
    mySubmenu->addAction(pAction);
     
    pAction = new QAction("Option 2");
    pAction->setCheckable(true);
    pAction->setChecked(isChecked());
    connect(pAction, &QAction::triggered, this, [=](bool checked) { onSubmenuClick(); } );
    mySubmenu->addAction(pAction);
    
    joeQJ 1 Reply Last reply
    0
    • Q Qtim

      How do I change the style of checkboxes for checkable QActions in a QMenu?

      My menu works as expected but the checks are checkmarks with no boxes. I want to see empty box and checked box.

      My menu has this:
      alt text

      But I want this:
      alt text

      QMenu* mySubmenu = addMenu(tr("MySubmenu"));
      QAction *pAction;
       
      pAction = new QAction("Option 1");
      pAction->setCheckable(true);
      pAction->setChecked(isChecked());
      connect(pAction, &QAction::triggered, this, [=](bool checked) { onSubmenuClick(); } );
      mySubmenu->addAction(pAction);
       
      pAction = new QAction("Option 2");
      pAction->setCheckable(true);
      pAction->setChecked(isChecked());
      connect(pAction, &QAction::triggered, this, [=](bool checked) { onSubmenuClick(); } );
      mySubmenu->addAction(pAction);
      
      joeQJ Offline
      joeQJ Offline
      joeQ
      wrote on last edited by joeQ
      #2

      @Qtim hi,friend,welcome.

      First tell you some Qt key words of Qt Style Sheets and Qt Style Sheets Reference,you can search them in Qt help manual. maybe will help you in the some days;

      From the Qt key words Qt Style Sheets Reference, you will find below description:

      List of Sub-Controls

      ::item 
      An item of a QAbstractItemView, a QMenuBar, a QMenu, or a QStatusBar.
      

      List of Pseudo-States

      :checked 
      The item is checked. For example, the checked state of QAbstractButton.
      :unchecked 
      The item is unchecked.
      

      I find one snippet from internet, maybe help you.

      /*Qmenu Style Sheets*/
      
       QMenu {
       background-color: white; /* sets background of the menu :white*/
       border: 1px solid white;
       }
      
       QMenu::item {
       /* sets background of menu item. set this to something non-transparent
       if you want menu color and menu item color to be different */
       background-color: transparent;
       padding:8px 32px;
       margin:0px 8px;
       border-bottom:1px solid #DBDBDB;
       }
      
       QMenu::item:selected { /* when user selects item using mouse or keyboard */
       background-color: #2dabf9;
       background-image: url(:/images/hydro.png)
       }
      
       /** Note: below QSS */
       QMenu::item:checked {
       background-image: url(:/images/checked.png) /** Note: Here to set item checed */
       }
      
       QMenu::item:unchecked {
       background-image: url(:/images/unchecked.png) /** Note: Here to set item uncheced */
       }
      

      You will know how to set styles when you read Qt Style Sheets in Qt help manual.

      Reference

      jianshu.com

      Just do it!

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved