Unsolved Fit & Resizable QLCDNumber
-
@mrjj
Thanks for reply.QFrame* Frame1 = new QFrame; QLCDNumber* setLCDNum1 = new QLCDNumber(Frame1); QSpacerItem * spacer1 = new QSpacerItem(0,20, QSizePolicy::Preferred, QSizePolicy::Preferred); QVBoxLayout* layout1 = new QVBoxLayout; layout1->addSpacerItem(spacer1); layout1->addWidget(setLCDNum1); QLCDNumber* currentLCDNum1 = new QLCDNumber(Frame1); QSpacerItem * spacer2 = new QSpacerItem(10,0, QSizePolicy::Preferred, QSizePolicy::Preferred); QHBoxLayout* layout2 = new QHBoxLayout; layout2->addLayout(layout1); layout2->addSpacerItem(spacer2); layout2->addWidget(currentLCDNum1); Frame1->setLayout(layout2); Frame1->show();
For instance;
"Width of second LCDNum" = 0.75 * "Width of Main LCDNum" -
Hi
You could use setMaximumWidth and limit it to 0.75 other the other.
You would need to catch any resize events for the parent form to redo calcualtion
if space available is changed and first LCD changes size. -
@mrjj
Thanks,
but I can't extract the accurate dimensions to do calculation (as mentioned in first post). -
@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