Solved QmenuBar
-
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) -
@Oumayma Sorry, the result is this:
Tamaño1: QSize(210, 188)
Tamaño2: QSize(203, 188)
Tamaño3: QSize(195, 64)
Tamaño4: QSize(195, 122)
Tamaño5: QSize(195, 64) -
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.
-
@SGaist
Hello again, I would like to ask if there is any function for QT in c / c ++ that performs the same functionality as in QML, the function I am talking about is implicitwidth /
implicitheight. thanks -
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.
-
@SGaist I'm new to QT and I was looking for an example of a text editor and that example was implemented in a mainwindow.
Your are helping me a lot. I will follow your advice and implement a personalized Qmenubar. Thank you.