Unsolved Fit & Resizable QLCDNumber
-
@CodeFreaks
Its not using a font so u cant get its size for the digits.
See here
https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qlcdnumber.cpp.html -
Thanks,
but why "contentsRect()" doesn't return the accurate width and height of widgets, too? -
Hi
it should be make sure the widget is visible before you read it. -
Hi,
Thanks for reply.if(currentLCDNum1->isVisible()){ cout<<"Main LCD W: "<<myLCDRect.width()<<" H: "<<myLCDRect.height()<<endl; }
Main LCD W: 96 H: 26
Am I doing wrong?
-
@CodeFreaks
Nope, looks good.
The reported sizes 96,26 is not correct ? -
@mrjj
Thanks,
No, it's not correct. I think the width of parent widget (Frame1) is 96 . Both QLCDNumbers reported the same height but as you can see in first post they are different, in size. -
@CodeFreaks
Hi I was wondering what myLCDRect is ? ( i read is a LCdNumber, but seems wrong, reading it again)
If its a QRect, you take before LCD is shown, it might no be correct.i made this test form
and didvoid MainWindow::on_pushButton_released() { qDebug() <<"Main LCD W: "<<ui->lcdNumber_1->width()<<" H: "<<ui->lcdNumber_1->height(); qDebug() <<"second LCD W: "<<ui->lcdNumber_2->width()<<" H: "<<ui->lcdNumber_2->height(); } result is. Main LCD W: 91 H: 31 second LCD W: 131 H: 71
Which seems pretty ok ?
-
@mrjj
Hi, thanks for reply.
Is there any way that we can achieve true sizes before they are shown?
If there isn't, How can we do that without user signals (pushbutton) ? -
@CodeFreaks
Hi
often they have sizeHint size but why you need this before shown ?I though goal was to let LED1.height be 0.75 of Led2.Height
or did i completely misunderstand the goal?
-
@mrjj
You are right,
If I can calculate the sizes before they are shown, without any events they will present with desire sizes at the beginning.
If a method exist which without any user signal, immediately after it is shown, reports the accurate sizes. It can be a good alternative, too. -
@CodeFreaks
Hi
You could make a custom widget based on QFrame and override
ResizeEvent and then set sizes for its LCD members.
http://doc.qt.io/qt-5/qwidget.html#resizeEvent