QmenuBar
-
You are getting the rectangle of the menu itself. Want you are looking for is the geometry of the thing with regard to the menu bar.
menuBar()->actionGeometry(menu->menuAction());
That said, why are you trying to paint over the QMenuBar from within the QMainWindow ? Depending on the customisation you want to make, it might be simpler to build a custom QMenuBar.
-
Hi,
What do you mean with QMenuBar options ?
-
@SGaist In the following video I show you an example of what I am trying to implement, maybe that way you will better understand what I need and you can give me a hand and thank you very much for your interest.
https://drive.google.com/file/d/1gY2_yFjtDrR_SvLtj-9zwsmSqkCrFOmv/view?usp=sharing -
@mrjjHello again, this sentence that you recommend to me has helped me to realize the following, that the QMenu have by default the width and height of the action with the largest size.
So that I understand if I want to draw a rectangle with the dimensions of the Qmenu = "File", I will not be able to do it because the size of that Qmenu is equal to its longest action in this case is "Save as". As you can see in the images, there is some way in which I can paint a rectangle with the dimensions of the Qmenu = "file".
If I do not explain myself well let me know and I will try to explain myself in another way, thanks for the help. -
Did you print the size of all the menus ?
-
@SGaist yes, I have done it in the following way:
qDebug()<<"Tamaño1:"<<ui->menuArchivo->size();
qDebug()<<"Tamaño2:"<<ui->menuEdicion->size();
qDebug()<<"Tamaño3:"<< ui->menuOir->size();
qDebug()<<"Tamaño4:"<<ui->menuHerramientas->size();
qDebug()<<"Tamaño5:"<<ui->menuAyuda->size();And this is the result:
Tamaño1: QSize(210, 188)
Tamaño2: QSize(100, 30)
Tamaño3: QSize(100, 30)
Tamaño4: QSize(100, 30)
Tamaño5: QSize(100, 30) -
As you can see from this, all the menu have different sizes.
So their geometry are different as well. Your rectangle issue has likely to do with a selection issue. -
@SGaist But as I mentioned before, these sizes correspond to the action with the largest size. and I need the size of the menu in question, I don't know if I can explain myself.
I put the video back to you so you know what I want this for.
https://drive.google.com/file/d/1gY2_yFjtDrR_SvLtj-9zwsmSqkCrFOmv/view?usp=sharing -
Then please provide a minimal compilable example that shows what you are doing.
-
@SGaist
These are the functions for the rectangle:void MainWindow::paintEvent(QPaintEvent *e){
Q_UNUSED(e);
QPainter MyPainter(this);
relleno(&MyPainter);}
void MainWindow::relleno(QPainter *paint){
QList<QMenu*> Menus = ui->menubar->findChildren<QMenu*>(); paint->fillRect(Menus.at(0)->rect(),QBrush("#c56c00"));
}
With the following I see the sizes:
void MainWindow::Debug(){
QList<QMenu*> Menus = ui->menubar->findChildren<QMenu*>(); qDebug()<<"Tamaño1:"<<ui->menuArchivo->size(); qDebug()<<"Tamaño2:"<<ui->menuEdicion->size(); qDebug()<<"Tamaño3:"<<ui->menuOir->size(); qDebug()<<"Tamaño4:"<<ui->menuHerramientas->size(); qDebug()<<"Tamaño5:"<<ui->menuAyuda->size(); }
and when I run the application this is the result:
I don't know if this helps you understand me.
-
You are getting the rectangle of the menu itself. Want you are looking for is the geometry of the thing with regard to the menu bar.
menuBar()->actionGeometry(menu->menuAction());
That said, why are you trying to paint over the QMenuBar from within the QMainWindow ? Depending on the customisation you want to make, it might be simpler to build a custom QMenuBar.
-