Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [Solved]Size of pushbuttons
Forum Updated to NodeBB v4.3 + New Features

[Solved]Size of pushbuttons

Scheduled Pinned Locked Moved Mobile and Embedded
24 Posts 5 Posters 16.3k 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.
  • R Offline
    R Offline
    rokemoon
    wrote on last edited by
    #6

    What if like that
    @cellBut[i][j]->size().height()@

    1 Reply Last reply
    0
    • A Offline
      A Offline
      alfah
      wrote on last edited by
      #7

      chuck,

      size function will return what values? With respect to my code, could u tell me how to go about it to find the size of any one of the pushbuttons?

      Thank you

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rokemoon
        wrote on last edited by
        #8

        "size()":http://doc.qt.nokia.com/latest/qwidget.html#size-prop return "QSize":http://doc.qt.nokia.com/latest/qsize.html object, where you can call "height()":http://doc.qt.nokia.com/latest/qsize.html#height

        1 Reply Last reply
        0
        • A Offline
          A Offline
          alfah
          wrote on last edited by
          #9

          rokemoon

          :D I got it :D Thank you!!!

          Jus one more questions, the values i got was 480 n 640. could you tell me, wats the unit? i mean, mm?? px?? or wat???

          Thank you

          1 Reply Last reply
          0
          • R Offline
            R Offline
            rokemoon
            wrote on last edited by
            #10

            the value in px.
            If you solved your problem please mark title of the post like this
            [SOLVED] Size of pushbuttions

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chuck Gao
              wrote on last edited by
              #11

              I'm sorry alfah, i can not understand your English clearlly. But, the size() function will return the widget's size(as we know QSize), as Eddy mentioned before, i think you need know some concept of geometry/bounding-rect.

              [quote author="alfah" date="1311752432"]could u tell me how to go about it to find the size of any one of the pushbuttons?[/quote]

              what do you mean alfah ? Can you give us a more detailed description ?

              Chuck

              1 Reply Last reply
              0
              • C Offline
                C Offline
                Chuck Gao
                wrote on last edited by
                #12

                ok, you solve it. Good luck :D

                Chuck

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alfah
                  wrote on last edited by
                  #13

                  Hey everybody,

                  im sorry to restart this thread, but the following code gives me values 480 and 640
                  @
                  cellBut[i][j]=new QPushButton();
                  connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));
                  ht=cellBut[0][0]->size().height();
                  wd=cellBut[0][0]->size().width();
                  @

                  by no means this is the size of the buttons, think its the screen size!!!!

                  I need pushbutton ht and width

                  Thank you

                  1 Reply Last reply
                  0
                  • EddyE Offline
                    EddyE Offline
                    Eddy
                    wrote on last edited by
                    #14

                    did you use an iteration like :
                    @for(i = 0, i < max , ++i){
                    for(j=0, j<max, ++j){
                    //do your stuff
                    }
                    }@

                    Qt Certified Specialist
                    www.edalsolutions.be

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      alfah
                      wrote on last edited by
                      #15

                      eddy,

                      Yup i did,
                      @
                      for(int i=0;i<6;i++)
                      {
                      for(int j=0;j<7;j++)
                      {

                             cellBut[i][j]=new QPushButton();
                             connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));
                             ht=cellBut[i][j]->size().height();
                             wd=cellBut[i][j]->size().width();
                      
                          }
                      }
                      

                      @

                      ht and wd gives me 640 and 480 respectivvely. which i think is the screen size and not individual button size.
                      :(

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Chuck Gao
                        wrote on last edited by
                        #16

                        I think the problem is, you didn't set the pushbutton's size implicit. And you didn't use any layout management. So the value is not you want.

                        Chuck

                        1 Reply Last reply
                        0
                        • EddyE Offline
                          EddyE Offline
                          Eddy
                          wrote on last edited by
                          #17

                          what Chuck is saying is that you didn't use a parent or add them to a layout. That way they get a size.

                          have a look at this quick and dirty example:

                          @ int rows = 6;//this is convenient in case you want to alter the numbers
                          int cols = 7;
                          QPushButton* cellBut[rows][cols] ;

                          for(int i=0;i<rows;i++) {
                              for(int j=0;j<cols;j++)     {
                                  cellBut[i][j]=new QPushButton(this);    //remark the use of a parent here
                                  //        connect(cellBut[i][j],SIGNAL(clicked()),this,SLOT(onClickAction()));//better way see below
                          
                              }
                          }
                          qDebug() << cellBut[0][0]->size().height();
                          qDebug() << cellBut[0][0]->size().width();@
                          

                          you might have a look at "QSignalMapper":http://doc.qt.nokia.com/4.7/qsignalmapper.html#details. There is a nice example of what you try to achieve.

                          Qt Certified Specialist
                          www.edalsolutions.be

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            alfah
                            wrote on last edited by
                            #18

                            chuck,

                            Yea, I have not set size of the pushbutton, But since it has been created, why doesn it give me the current size of the button. That it should do right?

                            :( Is it necessary to specify the size of the button while creating them?

                            Thank you

                            alfah

                            1 Reply Last reply
                            0
                            • EddyE Offline
                              EddyE Offline
                              Eddy
                              wrote on last edited by
                              #19

                              in case you missed my topic :
                              have a look at my example. also the QSignalMapper link.

                              Qt Certified Specialist
                              www.edalsolutions.be

                              1 Reply Last reply
                              0
                              • A Offline
                                A Offline
                                alfah
                                wrote on last edited by
                                #20

                                :) Thanks Eddy,

                                Got tht one, size now is 100 and 30 which is kinda resonable :)

                                alfah

                                1 Reply Last reply
                                0
                                • EddyE Offline
                                  EddyE Offline
                                  Eddy
                                  wrote on last edited by
                                  #21

                                  You're welcome. I'm glad you made it.

                                  And did you have a look at the QSignalMapper example?
                                  This will make your signal slots handling much easier.

                                  Qt Certified Specialist
                                  www.edalsolutions.be

                                  1 Reply Last reply
                                  0
                                  • A Offline
                                    A Offline
                                    alfah
                                    wrote on last edited by
                                    #22

                                    :)

                                    I checked that, :) its a lot more easier.

                                    Thank you :) :)

                                    1 Reply Last reply
                                    0
                                    • C Offline
                                      C Offline
                                      Chuck Gao
                                      wrote on last edited by
                                      #23

                                      Anyway, Enjoy Qt alfah :D

                                      Chuck

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        alfah
                                        wrote on last edited by
                                        #24

                                        chuck,

                                        :) well, im a beginner in Qt, so far it hasn been an enjoyment :),
                                        gradually i hope i will love bugs:D

                                        :)

                                        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