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 to implement a filling-space QAction's icon?

How to implement a filling-space QAction's icon?

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 1.2k Views 1 Watching
  • 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.
  • LimerL Offline
    LimerL Offline
    Limer
    wrote on last edited by Limer
    #1

    Firstly, please take a look at the qt-creator's filling-space QAction's icon,

    0_1543146349274_8.gif

    I draw a svg file, just as the below,

    0_1543146482940_20181125_194758.png

    I used it as a QAction's icon, but when I ran my program, it looked that the icon didn't fill the space apparently.

    0_1543146520898_9.gif

    The codes is as below,

    QMenu* languagesMenu = menuBar->addMenu(tr("Languages"));
    connect(languagesMenu, &QMenu::triggered, this, &MainWindow::changeLanguageSlot);
    languagesMenu->addAction(QIcon(":/images/dot_hover.svg"), tr("(System Language)"));
    languagesMenu->addSeparator();
    languagesMenu->addAction(tr("English"));
    languagesMenu->addAction(tr("Simplified Chinese"));
    

    Why? Could someone give me any advice?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Question not very clear. Do you want the ICON or highlighter ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      LimerL 1 Reply Last reply
      0
      • dheerendraD dheerendra

        Question not very clear. Do you want the ICON or highlighter ?

        LimerL Offline
        LimerL Offline
        Limer
        wrote on last edited by
        #3

        @dheerendra ICON,The reason to move the mouse back and forth, just a habit, sorry for that.

        1 Reply Last reply
        0
        • dheerendraD Offline
          dheerendraD Offline
          dheerendra
          Qt Champions 2022
          wrote on last edited by
          #4

          I can see ICON in your UI. So what is the issue ?

          Dheerendra
          @Community Service
          Certified Qt Specialist
          http://www.pthinks.com

          LimerL 1 Reply Last reply
          0
          • dheerendraD dheerendra

            I can see ICON in your UI. So what is the issue ?

            LimerL Offline
            LimerL Offline
            Limer
            wrote on last edited by
            #5

            @dheerendra Take a careful comparison between the pic1's icon and pic3's icon (the icons refer to the ones with blue background-color), the pic3's icon didn't fill all the space.

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Qt Champions 2022
              wrote on last edited by
              #6

              You are specifying only one ICON. Where is the pic3 icon ? I did not see the code to set the pic3 icon.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              http://www.pthinks.com

              1 Reply Last reply
              0
              • Chris KawaC Online
                Chris KawaC Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by Chris Kawa
                #7

                @Limer The blue rectangle in your first picture is not from the icon. It is the background of a checkable action when it is checked. The icon is actually smaller than that. It just has a transparent background so you can't see it.
                To get the same effect just make the background of your icon transparent and leave only the black dot.

                QAction* act = languagesMenu->addAction(QIcon(":/images/dot_hover.svg"), tr("(System Language)"));
                act->setCheckable(true);
                act->setChecked(true);
                

                Btw. a dot is not a very good choice of icon for language setting. It looks more like a radio button. For language I would suggest something like a speech bubble or some letters.

                LimerL 1 Reply Last reply
                5
                • Chris KawaC Chris Kawa

                  @Limer The blue rectangle in your first picture is not from the icon. It is the background of a checkable action when it is checked. The icon is actually smaller than that. It just has a transparent background so you can't see it.
                  To get the same effect just make the background of your icon transparent and leave only the black dot.

                  QAction* act = languagesMenu->addAction(QIcon(":/images/dot_hover.svg"), tr("(System Language)"));
                  act->setCheckable(true);
                  act->setChecked(true);
                  

                  Btw. a dot is not a very good choice of icon for language setting. It looks more like a radio button. For language I would suggest something like a speech bubble or some letters.

                  LimerL Offline
                  LimerL Offline
                  Limer
                  wrote on last edited by
                  #8

                  @Chris-Kawa Yes, you are right, thanks very much.

                  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