Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Fit & Resizable QLCDNumber
Forum Updated to NodeBB v4.3 + New Features

Fit & Resizable QLCDNumber

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CodeFreaksC Offline
    CodeFreaksC Offline
    CodeFreaks
    wrote on last edited by CodeFreaks
    #1

    Hi everyone,
    I want to add two LCDNumber which the font/frame size of one be ratio of another.

        QRect myLCDRect = currentLCDNum1->contentsRect();
        QRect myLCDRect2 = setLCDNum1->contentsRect();
        QRect widgetRect = Frame1->contentsRect();
    
        QFont myFont1 = currentLCDNum1->font();
        QFont myFont2 = setLCDNum1->font();
    
        cout<<"Main   LCD  W: "<<myLCDRect.width()<<"   H: "<<myLCDRect.height()<<endl;
        cout<<"second LCD  W: "<<myLCDRect2.width()<<"   H: "<<myLCDRect2.height()<<endl;
        cout<<"Main Widget W: "<<widgetRect.width()<<"   H: "<<widgetRect.height()<<endl;
        cout<<endl;
        cout<<"Main   Font: "<<myFont1.pixelSize()<<endl;
        cout<<"second Font: "<<myFont2.pixelSize()<<endl;
    
    Main   LCD  W: 96   H: 26
    second LCD  W: 96   H: 26
    Main Widget W: 636   H: 476
    
    Main   Font: -1
    second Font: -1
    

    These outputs aren't acceptable.

    0_1534688901987_Qln.png

    I don't have any idea how can I do this!

    1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      Did you apply layout to the parent of the LCDs ?
      alt text

      Im not sure what you mean by

      • size of one be a ratio of another.
      CodeFreaksC 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Did you apply layout to the parent of the LCDs ?
        alt text

        Im not sure what you mean by

        • size of one be a ratio of another.
        CodeFreaksC Offline
        CodeFreaksC Offline
        CodeFreaks
        wrote on last edited by
        #3

        @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"

        1 Reply Last reply
        1
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          CodeFreaksC 1 Reply Last reply
          1
          • mrjjM mrjj

            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.

            CodeFreaksC Offline
            CodeFreaksC Offline
            CodeFreaks
            wrote on last edited by CodeFreaks
            #5

            @mrjj
            Thanks,
            but I can't extract the accurate dimensions to do calculation (as mentioned in first post).

            mrjjM 1 Reply Last reply
            0
            • CodeFreaksC CodeFreaks

              @mrjj
              Thanks,
              but I can't extract the accurate dimensions to do calculation (as mentioned in first post).

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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

              1 Reply Last reply
              2
              • CodeFreaksC Offline
                CodeFreaksC Offline
                CodeFreaks
                wrote on last edited by CodeFreaks
                #7

                Thanks,
                but why "contentsRect()" doesn't return the accurate width and height of widgets, too?

                mrjjM 1 Reply Last reply
                0
                • CodeFreaksC CodeFreaks

                  Thanks,
                  but why "contentsRect()" doesn't return the accurate width and height of widgets, too?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi
                  it should be make sure the widget is visible before you read it.

                  1 Reply Last reply
                  1
                  • CodeFreaksC Offline
                    CodeFreaksC Offline
                    CodeFreaks
                    wrote on last edited by CodeFreaks
                    #9

                    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?

                    mrjjM 1 Reply Last reply
                    0
                    • CodeFreaksC CodeFreaks

                      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?

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @CodeFreaks
                      Nope, looks good.
                      The reported sizes 96,26 is not correct ?

                      CodeFreaksC 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @CodeFreaks
                        Nope, looks good.
                        The reported sizes 96,26 is not correct ?

                        CodeFreaksC Offline
                        CodeFreaksC Offline
                        CodeFreaks
                        wrote on last edited by CodeFreaks
                        #11

                        @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.

                        mrjjM 1 Reply Last reply
                        0
                        • CodeFreaksC CodeFreaks

                          @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.

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @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
                          alt text
                          and did

                          void 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 ?

                          CodeFreaksC 1 Reply Last reply
                          1
                          • mrjjM mrjj

                            @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
                            alt text
                            and did

                            void 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 ?

                            CodeFreaksC Offline
                            CodeFreaksC Offline
                            CodeFreaks
                            wrote on last edited by CodeFreaks
                            #13

                            @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) ?

                            mrjjM 1 Reply Last reply
                            0
                            • CodeFreaksC CodeFreaks

                              @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) ?

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @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?

                              CodeFreaksC 1 Reply Last reply
                              1
                              • mrjjM mrjj

                                @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?

                                CodeFreaksC Offline
                                CodeFreaksC Offline
                                CodeFreaks
                                wrote on last edited by CodeFreaks
                                #15

                                @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.

                                mrjjM 1 Reply Last reply
                                0
                                • CodeFreaksC CodeFreaks

                                  @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.

                                  mrjjM Offline
                                  mrjjM Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @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

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved