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. QMenuBar in QMainWindow Styling issue
Forum Updated to NodeBB v4.3 + New Features

QMenuBar in QMainWindow Styling issue

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.7k 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.
  • D Offline
    D Offline
    Dark4326
    wrote on last edited by
    #1

    Hi, Im fairly new to Qt and I'm trying to style the QMenuBar in my QMainWindow. However when I add a QMenu to the QMenuBar the styling doesn't seem to follow through. I have tried multiple approaches including style sheets at palettes using examples listed elsewhere. Here is the what the bar looks like currently and some code. Any help as to why this is happening is appreciated.

    !http://i.imgur.com/9iZhk.png(The area under 'File' should also be gradient)!

    mFileMenu is a QMenu
    myMenuBar is a QMenuBar

    @
    mFileMenu = new QMenu(tr("File"));
    QString s1("QMenuBar{ background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1,stop:0 darkgrey, stop:1 black); color: white}");
    myMenuBar->setStyleSheet(s1);
    myMenuBar->addMenu(mFileMenu);
    @

    I then use setMenuBar in my QMainWindow to set myMenuBar the menuBar

    1 Reply Last reply
    0
    • J Offline
      J Offline
      joonhwan
      wrote on last edited by
      #2

      Please check the image link. cannot see it here.

      joonhwan at gmail dot com

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        Hi Dark4326

        I tried to fix your link, but seems there is nog image there. Are you sure that you uploaded an image there or is it private?

        "The forum help gives some more assistance":http://developer.qt.nokia.com/wiki/ForumHelp#9bd9c32b79efb1b2d5b039e4d48300a9

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • D Offline
          D Offline
          Dark4326
          wrote on last edited by
          #4

          I think I have fixed the image issue, thanks for your replies.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            joonhwan
            wrote on last edited by
            #5

            In my case, the highlited part of hovered menu item doesn't look like yours. It seems to be relevant to desktop configuration of your OS. In my old windows xp desktop, I can change the background color of 'File' menu when mouse hovering over there via control panel > display > ....
            BTW, do we have a kind of 'transparent' higlighted menu item attribute? such things would be helpful.

            joonhwan at gmail dot com

            1 Reply Last reply
            0
            • J Offline
              J Offline
              joonhwan
              wrote on last edited by
              #6

              Though quite old topic, I found how to control the menubar's painting via palette in this case.
              The color of "File" menu while mouse is over it is QPalette::Higlight color, so you just can change it.
              see.. in the qwindowsxpstyles.cpp code

              @
              void QWindowsXPStyle::drawControl(ControlElement element, const QStyleOption *option, QPainter *p,
              const QWidget *widget) const
              {
              .
              .
              case CE_MenuBarItem:
              if (const QStyleOptionMenuItem *mbi = qstyleoption_cast<const QStyleOptionMenuItem *>(option))
              {
              if (mbi->menuItemType == QStyleOptionMenuItem::DefaultItem)
              break;

                      bool act = mbi->state & State_Selected;
                      bool dis = !(mbi->state & State_Enabled);
              
                      QBrush fill = mbi->palette.brush(act ? QPalette::Highlight : QPalette::Button);
                      QPalette::ColorRole textRole = dis ? QPalette::Text:
                                                     act ? QPalette::HighlightedText : QPalette::B
              

              .
              .
              @

              The 'fill' brush is the one that make your menubar ugly in your case(but it is due to your desktop configuration not Qt, i think).

              I just did

              @
              QPalette palette = this->menuBar()->palette();
              palette.setBrush(QPalette::Highlight, QBrush(QColor(100,100,100,100)));
              @

              and feel like it is much better in the gradient background.

              joonhwan at gmail dot com

              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