Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Solved Show SVG file in QMenuBar corner part

    General and Desktop
    2
    6
    812
    Loading More Posts
    • 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 C
      Romain C last edited by kshegunov

      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 Reply Quote 0
      • ?
        A Former User last edited by

        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 Reply Quote 3
        • Romain C
          Romain C last edited by

          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 Reply Quote 0
          • ?
            A Former User last edited by

            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 Reply Quote 3
            • Romain C
              Romain C last edited by

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

              1 Reply Last reply Reply Quote 0
              • Romain C
                Romain C last edited by Romain C

                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 Reply Quote 0
                • First post
                  Last post