QMenuBar corner widget not aligned to right edge
-
Trying to add a button as corner widget. In Qt Designer I created the menubar and button (but its not assigned to layout etc). Then in constructor, I'm calling
ui.menu->setCornerWidget(ui.cornerbutton);
but there is always some spacing on the right side of button, how do I adjust the margin/spacing on right?
-
Figured out the problem. Essentially what's happening is that Qt is going by some minimum width (~200px). Since I was setting button width around 50px, the remaining space was showing up as margin/spacing between button and edge.
Solution is to either increase the width of the button or add it to a layout inside another widget, and set that widget as corner widget, so even if Qt resizes the widget to a larger size, the button inside can still remain the desired width.
-
Hi,
Based on the method documentation the widget is out right after the rightmost item in the menu bar so it's likely what you see.
-
Hi,
Based on the method documentation the widget is out right after the rightmost item in the menu bar so it's likely what you see.
@SGaist The menubar has 4 items and when window opens its maximized, so there is a lot of space between last menubar item and corner widget/button. Its weird that it isnt positioned to right edge.
This guy seems to be having the same issue: https://stackoverflow.com/questions/48361829/remove-offset-of-cornerwidget-in-qmenubar
-
Figured out the problem. Essentially what's happening is that Qt is going by some minimum width (~200px). Since I was setting button width around 50px, the remaining space was showing up as margin/spacing between button and edge.
Solution is to either increase the width of the button or add it to a layout inside another widget, and set that widget as corner widget, so even if Qt resizes the widget to a larger size, the button inside can still remain the desired width.