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 remove text section in QAction inside QMenu?

How to remove text section in QAction inside QMenu?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.1k 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.
  • T Offline
    T Offline
    thebeast44
    wrote on last edited by
    #1

    Hi all,

    I'm creating a custom context menu for my application.

    @
    const static QColor colors[5] = { QColor(231,216,124,85), QColor(214,149,156,85), QColor(190,211,112,85), QColor(124,185,200,85), QColor(190,147,204,85) };
    @

    @
    QPixmap pixmap(16,16);
    pixmap.fill(colors[colorIndex_]);
    QMenu *selectColor = new QMenu(tr("Colors"), this);
    selectColor->setIcon(QIcon(pixmap));

    QList<QAction *> colorList;
    for (int i = 0; i < 5; i++) {
        pixmap.fill(colors[i]);
        QAction *color = new QAction(QIcon(pixmap), "", this);
        color->setData(QVariant(i));
        colorList.append(color);
    }
    selectColor->addActions(colorList);
    menu->addMenu(selectColor);
    

    @

    Using the code above, I tried to create a color selection menu with 16 by 16 icon only.
    This works fine in Mac using Qt 5.3 but when I try the same code in Windows 7 using Qt 5.3,

    !http://i.imgur.com/4oKyHbc.jpg!

    the menu show a separator and huge blank space to the right.

    I'm not sure if this is a bug or some requirement for Windows UI guideline or something.

    Does anyone know how to get rid of that blank space?

    Thank you.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Looks a bit fishy, can you try again with

      @QAction *color = new QAction(QIcon(pixmap), QString(), this);@

      to see if it changes something

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thebeast44
        wrote on last edited by
        #3

        [quote author="SGaist" date="1401490814"]Hi,

        Looks a bit fishy, can you try again with

        @QAction *color = new QAction(QIcon(pixmap), QString(), this);@

        to see if it changes something[/quote]

        Thanks for the suggestion.
        I tried QString() as you've suggested and also 0 but didn't make any difference.
        I think I'll just have to come up with some text to go along with the colors.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          In between you can show the color name.

          I can't tell if it's a windows limitation, however you could check the "bug report system":http://bugreports.qt-project.org to see if it's something known

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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