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. Make changes in buttons' shapes and sizes in a gridlayout
Forum Updated to NodeBB v4.3 + New Features

Make changes in buttons' shapes and sizes in a gridlayout

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 773 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.
  • tomyT Offline
    tomyT Offline
    tomy
    wrote on last edited by tomy
    #1

    Hi guys,

    This is a for loop of the code positioning and giving sizes to 22 buttons:

    for(int i=0; i<texts.size(); ++i)
          {
             QPushButton* button = new QPushButton(texts[i]);
    
             connect(button, SIGNAL(clicked(bool)),
                     signalMapper, SLOT(map()));
    
             signalMapper -> setMapping(button, texts[i]);
             gridLayout -> addWidget(button, i/5, i%5);
          }
    

    The result is in as follows:
    http://uploads.im/M1KOV.png

    First I want to make buttons smaller.
    Then to arrange them by manually giving them coordinates.

    How to do these please? Should I firstly remove the gridlayout?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Carmoneer
      wrote on last edited by Carmoneer
      #2

      Re: Make changes in buttons' shapes and sizes in a gridlayout

      One way to do it:

      Pass the parent 'this' during initialization of the buttons and then move them as desired.

      QPushButton** buttonArray;
      buttonArray = new QPushButton*[22];
      
      for(int i=0; i<texts.size(); ++i)
            {
               buttonArray[i] = new QPushButton(texts[i], this);
      
               connect(buttonArray[i], SIGNAL(clicked(bool)),
                       signalMapper, SLOT(map()));
      
               signalMapper -> setMapping(buttonArray[i], texts[i]);
            }
      
      buttonArray[i]->move(xPos, yPos);
      

      As for making the buttons smaller, take a look atQWidget Class for setting max or fixed sizes.

      tomyT 1 Reply Last reply
      0
      • C Carmoneer

        Re: Make changes in buttons' shapes and sizes in a gridlayout

        One way to do it:

        Pass the parent 'this' during initialization of the buttons and then move them as desired.

        QPushButton** buttonArray;
        buttonArray = new QPushButton*[22];
        
        for(int i=0; i<texts.size(); ++i)
              {
                 buttonArray[i] = new QPushButton(texts[i], this);
        
                 connect(buttonArray[i], SIGNAL(clicked(bool)),
                         signalMapper, SLOT(map()));
        
                 signalMapper -> setMapping(buttonArray[i], texts[i]);
              }
        
        buttonArray[i]->move(xPos, yPos);
        

        As for making the buttons smaller, take a look atQWidget Class for setting max or fixed sizes.

        tomyT Offline
        tomyT Offline
        tomy
        wrote on last edited by
        #3

        @Carmoneer
        Thank you. I set fixed size for the buttons and they appear better now.
        But about positioning, your solution is a bit advanced for me as a newcomer to Qt.

        Please read this scenario:
        Can't I use a vector of strings and then put the strings ("2", "3", "+", "/" and the rest) into it and by a for loop call a function for the work?

        That way I could set the size and position individually for each button manually.

        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