Show SVG file in QMenuBar corner part



  • 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]


  • Moderators

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



  • 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


  • Moderators

    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.



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



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.