Important: Please read the Qt Code of Conduct -

Menubuttons with fixed width / max-width for varying titletext

  • Hi!

    The ebook management program calibre uses Qt to display its UI (calibre sourcecode).

    Calibre screenshot:
    0_1526921265253_Screenshot (140).png

    Is it possible to limit the top menubutton's size either to a fixed width or a max-width?
    Fixed width would look much cleaner and max-width is the standard for MS Windows ribbon design.

    The thing is that according to the translation the text changes and word-wrap at spaces (and slashes?) is needed.

    An example:

    Quote calibre dev:

    feel free to propose it to the Qt (Qt is what calibre uses for its widgets) developers. They will need to add such an option to the QToolBar/QToolButton/QMenuBar classes.

    Thanks for help,

  • Lifetime Qt Champion

    Hi and welcome to the forums.
    You mean you want it to dynamic word wrap and not
    use \n for it ?
    alt text

    setMaximumWidth already exists but for the word wrap, you would have to make a custom QToolButton and handle it yourself. Also you might need to
    override sizeHint() too as as far as i recall it looks at the text and will be unaware if
    you word wrap it in paintEvent.

  • Thank you for your reply.

    You mean you want it to dynamic word wrap and not use \n for it ?

    Yes, but now as you name it, I consider it an easy workaround to hardcode the \n. I don't know why anyone would like extremely wide buttons better than 2 lines with a minimal loss in vertical space.

    Combined with setMaximumWidth that's already an acceptable solution to me. I'll forward it to the calibre devs and may ask back.

    I hope I don't forget it, but if you don't hear back from me the next two weeks, you can close this as solved :-)

    Thank you!

    p.s.: Do you have a link to the wiki for me? I clicked around a bit but I'm insecure if I've found the right articles. I'm not a dev in that field. I guess there's also a setMinimumWidth?

  • Ok, the calibre dev already has solved the issue.
    Thanks for your help!

  • Lifetime Qt Champion

    Ok super. So you got your more compact buttons?
    Seems like a nice project.

Log in to reply