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. Show SVG file in QMenuBar corner part
Forum Updated to NodeBB v4.3 + New Features

Show SVG file in QMenuBar corner part

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.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.
  • Romain CR Offline
    Romain CR Offline
    Romain C
    wrote on last edited by kshegunov
    #1

    Hi everyone,
    I'm working on an app, and I want to use a QMainWindow as a frameless window.
    So we want to display a logo front to the QMenuBar of this QMainWindow.

    Can you give a me the (best) way to draw an SVG image in the top left corner part of the menu bar?

    This what I wrote:

    QSvgWidget* widget = new QSvgWidget(":/WaveView/icon/appBig.svg",container);
    p_customBar->setCornerWidget(widget, Qt::TopLeftCorner);
    

    The problem of this solution, is the image don't fit to the parent QMenuBar (the QToolBar fit to the height of the QSvgWidget, and became ugly).
    In the best way, I want my icon fit height of toolbar and keep his ratio.

    Best regards,
    Romain

    [Moved to General and Desktop, added code tags ~kshegunov]

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Haven't tested it, maybe it works if you set the QSvgWidget's maximumHeight to the height returned by QToolbar::iconSize().

      1 Reply Last reply
      3
      • Romain CR Offline
        Romain CR Offline
        Romain C
        wrote on last edited by
        #3

        Yeah! I think it would work too. But I want my component to be dynamic, I explain:
        I want my component to be resize if somebody through the code says for example "hey MenuBar change your height". I can do retro control mecanism, but I want in a first time to avoid crapy complex code if something already does it you know! =D
        If is the only way, I will do something like this.
        Thanks for youre answer

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          QToolbar has a property "iconSize" and QSvgWidget has a property "size". If my first suggestion turns out to work at all then you can use signals and slots to get automatic adjustment of size.

          1 Reply Last reply
          3
          • Romain CR Offline
            Romain CR Offline
            Romain C
            wrote on last edited by
            #5

            Ok I will try this mecanism and I will be back after that, thx Wieland!

            1 Reply Last reply
            0
            • Romain CR Offline
              Romain CR Offline
              Romain C
              wrote on last edited by Romain C
              #6

              Ok at least I used finally an QLabel:

              //Create our label that contain icon
              QLabel* iconLabel = new QLabel(p_customBar);
              QIcon icon(":/WaveView/icon/applicationLogoBig.svg");
              iconLabel->setPixmap(icon.pixmap(QSize(52,52)));
              //setPixmap(const QPixmap &)
              p_customBar->setCornerWidget(iconLabel, Qt::TopLeftCorner);

              I'm little embarrased because I have to precise an arbitrary size for QIcon to pixamp, but the component keep the ratio, fit the toolbar height, etc...
              But I reuse internal behaviour and I don't have to make some tricky code.
              Thx for answers
              Best regards

              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