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. Problem with somes QPushButton size
Forum Updated to NodeBB v4.3 + New Features

Problem with somes QPushButton size

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 1.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.
  • F Offline
    F Offline
    Fulgurance
    wrote on last edited by Fulgurance
    #1

    Hello, actually i make management software for a friend. But i have little problem. When i specify rowSpan and columnSpan into layout, it's not applied good.

    I would like the 3 first buttons (sell, stock and invoices buttons) have columnSpawn and rowSpawn with size of 2

    Buttons into QGroupBox and at the bottom of this box with columSpawn and rowSpan with size 1

    But when i test my application, the height of my 3 first QPushButton isn't changed, and picture don't follow the button size.
    Why ?
    (just a little other question, have i right to don't specify parents to my pointers ?)

    #include "mainwindow.h"
    
    MainWindow::MainWindow() : QWidget()
    {
        initialize();
        create_buttons();
        create_layouts();
        create_management_groupbox();
    }
    
    void MainWindow::initialize()
    {
        setWindowTitle("Caisse");
        //setWindowIcon(QIcon(""));
        setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
        initialize_pointers();
        setLayout(main_layout);
    }
    
    void MainWindow::initialize_pointers()
    {
        main_layout = new QGridLayout;
        sell_button = new QPushButton;
        stock_button = new QPushButton;
        invoices_button = new QPushButton;
        management_groupbox = new QGroupBox;
        management_layout = new QGridLayout;
        products_button = new QPushButton;
        services_button = new QPushButton;
        employees_button = new QPushButton;
        suppliers_button = new QPushButton;
        customers_button = new QPushButton;
        settings_button = new QPushButton;
        help_button = new QPushButton;
    }
    
    void MainWindow::create_layouts()
    {
        create_main_layout();
        create_management_layout();
    }
    
    void MainWindow::create_main_layout()
    {
        main_layout->addWidget(sell_button,0,0,2,2);
        main_layout->addWidget(stock_button,0,2,2,2);
        main_layout->addWidget(invoices_button,0,4,2,2);
        main_layout->addWidget(management_groupbox,2,0,1,6);
        main_layout->addWidget(settings_button,4,4,1,1);
        main_layout->addWidget(help_button,4,5,1,1);
    }
    
    void MainWindow::create_management_layout()
    {
        management_layout->addWidget(products_button,0,0,1,1);
        management_layout->addWidget(services_button,0,1,1,1);
        //Need separator here
        management_layout->addWidget(employees_button,1,0,1,1);
        management_layout->addWidget(suppliers_button,1,1,1,1);
        management_layout->addWidget(customers_button,1,2,1,1);
    }
    
    void MainWindow::create_management_groupbox()
    {
        management_groupbox->setParent(this);
        management_groupbox->setTitle("Gestion");
        management_groupbox->setLayout(management_layout);
    }
    
    void MainWindow::create_buttons()
    {
        create_sell_button();
        create_stock_button();
        create_invoices_button();
        create_products_button();
        create_services_button();
        create_employees_button();
        create_suppliers_button();
        create_customers_button();
        create_settings_button();
        create_help_button();
    }
    
    void MainWindow::create_sell_button()
    {
        sell_button->setIcon(QIcon("Pictures/Sell.png"));
        sell_button->setToolTip("Interface de vente");
    }
    
    void MainWindow::create_stock_button()
    {
        stock_button->setIcon(QIcon("Pictures/Stock.png"));
        stock_button->setToolTip("Gestion des stocks");
    }
    
    void MainWindow::create_invoices_button()
    {
        invoices_button->setIcon(QIcon("Pictures/Invoices.png"));
        invoices_button->setToolTip("Consulter des factures");
    }
    
    void MainWindow::create_products_button()
    {
        products_button->setIcon(QIcon("Pictures/Products.png"));
        products_button->setToolTip("Gestions des produits");
    }
    
    void MainWindow::create_services_button()
    {
        services_button->setIcon(QIcon("Pictures/Services.png"));
        services_button->setToolTip("Gestion des services");
    }
    
    void MainWindow::create_employees_button()
    {
        employees_button->setIcon(QIcon("Pictures/Employees.png"));
        employees_button->setToolTip("Gestion des employés");
    }
    
    void MainWindow::create_suppliers_button()
    {
        suppliers_button->setIcon(QIcon("Pictures/Suppliers.png"));
        suppliers_button->setToolTip("Gestion des fournisseurs");
    }
    
    void MainWindow::create_customers_button()
    {
        customers_button->setIcon(QIcon("Pictures/Customers.png"));
        customers_button->setToolTip("Gestion des clients");
    }
    
    void MainWindow::create_settings_button()
    {
        settings_button->setIcon(QIcon("Pictures/Settings.png"));
        settings_button->setToolTip("Paramètres du logiciel");
    }
    
    void MainWindow::create_help_button()
    {
        help_button->setIcon(QIcon("Pictures/Help.png"));
        help_button->setToolTip("Centre d'aide");
    }
    
    

    Screenshot:
    Screenshot_20200726_163025.png

    In one sentence, why my button don't take all of the height ?

    Pl45m4P 1 Reply Last reply
    0
    • F Fulgurance

      Hello, actually i make management software for a friend. But i have little problem. When i specify rowSpan and columnSpan into layout, it's not applied good.

      I would like the 3 first buttons (sell, stock and invoices buttons) have columnSpawn and rowSpawn with size of 2

      Buttons into QGroupBox and at the bottom of this box with columSpawn and rowSpan with size 1

      But when i test my application, the height of my 3 first QPushButton isn't changed, and picture don't follow the button size.
      Why ?
      (just a little other question, have i right to don't specify parents to my pointers ?)

      #include "mainwindow.h"
      
      MainWindow::MainWindow() : QWidget()
      {
          initialize();
          create_buttons();
          create_layouts();
          create_management_groupbox();
      }
      
      void MainWindow::initialize()
      {
          setWindowTitle("Caisse");
          //setWindowIcon(QIcon(""));
          setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
          initialize_pointers();
          setLayout(main_layout);
      }
      
      void MainWindow::initialize_pointers()
      {
          main_layout = new QGridLayout;
          sell_button = new QPushButton;
          stock_button = new QPushButton;
          invoices_button = new QPushButton;
          management_groupbox = new QGroupBox;
          management_layout = new QGridLayout;
          products_button = new QPushButton;
          services_button = new QPushButton;
          employees_button = new QPushButton;
          suppliers_button = new QPushButton;
          customers_button = new QPushButton;
          settings_button = new QPushButton;
          help_button = new QPushButton;
      }
      
      void MainWindow::create_layouts()
      {
          create_main_layout();
          create_management_layout();
      }
      
      void MainWindow::create_main_layout()
      {
          main_layout->addWidget(sell_button,0,0,2,2);
          main_layout->addWidget(stock_button,0,2,2,2);
          main_layout->addWidget(invoices_button,0,4,2,2);
          main_layout->addWidget(management_groupbox,2,0,1,6);
          main_layout->addWidget(settings_button,4,4,1,1);
          main_layout->addWidget(help_button,4,5,1,1);
      }
      
      void MainWindow::create_management_layout()
      {
          management_layout->addWidget(products_button,0,0,1,1);
          management_layout->addWidget(services_button,0,1,1,1);
          //Need separator here
          management_layout->addWidget(employees_button,1,0,1,1);
          management_layout->addWidget(suppliers_button,1,1,1,1);
          management_layout->addWidget(customers_button,1,2,1,1);
      }
      
      void MainWindow::create_management_groupbox()
      {
          management_groupbox->setParent(this);
          management_groupbox->setTitle("Gestion");
          management_groupbox->setLayout(management_layout);
      }
      
      void MainWindow::create_buttons()
      {
          create_sell_button();
          create_stock_button();
          create_invoices_button();
          create_products_button();
          create_services_button();
          create_employees_button();
          create_suppliers_button();
          create_customers_button();
          create_settings_button();
          create_help_button();
      }
      
      void MainWindow::create_sell_button()
      {
          sell_button->setIcon(QIcon("Pictures/Sell.png"));
          sell_button->setToolTip("Interface de vente");
      }
      
      void MainWindow::create_stock_button()
      {
          stock_button->setIcon(QIcon("Pictures/Stock.png"));
          stock_button->setToolTip("Gestion des stocks");
      }
      
      void MainWindow::create_invoices_button()
      {
          invoices_button->setIcon(QIcon("Pictures/Invoices.png"));
          invoices_button->setToolTip("Consulter des factures");
      }
      
      void MainWindow::create_products_button()
      {
          products_button->setIcon(QIcon("Pictures/Products.png"));
          products_button->setToolTip("Gestions des produits");
      }
      
      void MainWindow::create_services_button()
      {
          services_button->setIcon(QIcon("Pictures/Services.png"));
          services_button->setToolTip("Gestion des services");
      }
      
      void MainWindow::create_employees_button()
      {
          employees_button->setIcon(QIcon("Pictures/Employees.png"));
          employees_button->setToolTip("Gestion des employés");
      }
      
      void MainWindow::create_suppliers_button()
      {
          suppliers_button->setIcon(QIcon("Pictures/Suppliers.png"));
          suppliers_button->setToolTip("Gestion des fournisseurs");
      }
      
      void MainWindow::create_customers_button()
      {
          customers_button->setIcon(QIcon("Pictures/Customers.png"));
          customers_button->setToolTip("Gestion des clients");
      }
      
      void MainWindow::create_settings_button()
      {
          settings_button->setIcon(QIcon("Pictures/Settings.png"));
          settings_button->setToolTip("Paramètres du logiciel");
      }
      
      void MainWindow::create_help_button()
      {
          help_button->setIcon(QIcon("Pictures/Help.png"));
          help_button->setToolTip("Centre d'aide");
      }
      
      

      Screenshot:
      Screenshot_20200726_163025.png

      In one sentence, why my button don't take all of the height ?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @Fulgurance said in Problem with somes QPushButton size:

      MainWindow::MainWindow() : QWidget()

      So your MainWindow is actually a QWidget and not a QMainWindow?! I'm just asking...

      @Fulgurance said in Problem with somes QPushButton size:

      don't specify parents to my pointers

      Yes, you dont need to set a parent. But it seems that you removed the possibility of setting one completely... I would keep that default nullptr in your header file. Instead of just doing this MainWindow() better do something like MainWindow(QWidget *parent = nullptr).

      @Fulgurance said in Problem with somes QPushButton size:

      why my button don't take all of the height

      You want your buttons look more like rectangles?!
      Set the vertical sizePolicy of your 3 buttons to expanding ( I guess, it's set to fixed at the moment )

      // get current size policy from button
      QSizePolicy btnPol = YOUR_BUTTON_PTR->sizePolicy();
      // set vertical size policy
      btnPol.setVerticalPolicy(QSizePolicy::Policy::Expanding);
      // add modified policy to your button again without changing anything else
      YOUR_BUTTON_PTR->setSizePolicy(btnPol);
      

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      1
      • F Offline
        F Offline
        Fulgurance
        wrote on last edited by
        #3

        @Pl45m4 said in Problem with somes QPushButton size:

        QSizePolicy::Policy::Expanding

        Thanks for your advice ! And if i would like picture are resized when QPushButton is resized ?

        Pl45m4P 1 Reply Last reply
        0
        • F Fulgurance

          @Pl45m4 said in Problem with somes QPushButton size:

          QSizePolicy::Policy::Expanding

          Thanks for your advice ! And if i would like picture are resized when QPushButton is resized ?

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by Pl45m4
          #4

          @Fulgurance

          You mean the icon?

          Unfortunately icons have a fixed size, but you can update them every time you resize your window / buttons.
          (https://www.qtcentre.org/threads/28187-How-to-resize-the-QIcon-inside-QPushButton-dynamically)

          OR (if you really want to do that)

          you can subclass QPushButton to make custom ones and edit their resizeEvents so that they update their icons automatically.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          1
          • F Offline
            F Offline
            Fulgurance
            wrote on last edited by
            #5

            Hum.. But now, why i have that ???
            Screenshot_20200726_163025.png
            I don't understand why i have this result, why the 3 first buttons haven't the same ???

            I have just doing that (for example for sell_button):

            sell_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
            

            (okay for picture, thanks)

            Pl45m4P 1 Reply Last reply
            0
            • F Fulgurance

              Hum.. But now, why i have that ???
              Screenshot_20200726_163025.png
              I don't understand why i have this result, why the 3 first buttons haven't the same ???

              I have just doing that (for example for sell_button):

              sell_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
              

              (okay for picture, thanks)

              Pl45m4P Offline
              Pl45m4P Offline
              Pl45m4
              wrote on last edited by
              #6

              @Fulgurance

              Is your mainLayout a QGridLayout?

              If one button expands, all other in the same row will expand too.

              How should it look like? Which buttons should be big and which should stay more bar-like?


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Fulgurance
                wrote on last edited by Fulgurance
                #7

                Yes it's QGridLayout.

                I would like that:

                test.png

                It's not visible in picture, but i would like middle buttons into groupbox have width with 1, and top button with width with 2

                Pl45m4P 1 Reply Last reply
                0
                • F Fulgurance

                  Yes it's QGridLayout.

                  I would like that:

                  test.png

                  It's not visible in picture, but i would like middle buttons into groupbox have width with 1, and top button with width with 2

                  Pl45m4P Offline
                  Pl45m4P Offline
                  Pl45m4
                  wrote on last edited by Pl45m4
                  #8

                  @Fulgurance

                  Like this?

                  Layout.png

                  This is the corresponding object tree...
                  All pushbuttons are vertical expanding, the bottom two (in HBox Layout) are vertical expanding and horizontal minimumExpanding

                  LayoutTree.png

                  EDIT:

                  Ah my bad... I messed up the GroupBox.... Did not see, that the top 3 buttons are not inside the groupBox...
                  But this shouldn't be a problem :)

                  This should be it :)
                  layoutNeu.png


                  If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                  ~E. W. Dijkstra

                  1 Reply Last reply
                  2
                  • F Offline
                    F Offline
                    Fulgurance
                    wrote on last edited by Fulgurance
                    #9

                    Yes like this, but just i would like the last two buttons are more small.

                    I have set to minimum expanding, but this don't change bug.

                    It's strange, i have tested, the 3 first buttons have good size when i don't put the 2 last buttons...

                    Look my code (i have just changed QPushButton to QToolButton for somes options):

                    #include "mainwindow.h"
                    
                    MainWindow::MainWindow() : QWidget()
                    {
                        initialize();
                        create_buttons();
                        create_layouts();
                        create_management_groupbox();
                    }
                    
                    void MainWindow::initialize()
                    {
                        setWindowTitle("Caisse");
                        //setWindowIcon(QIcon(""));
                        setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
                        initialize_pointers();
                        setLayout(main_layout);
                    }
                    
                    void MainWindow::initialize_pointers()
                    {
                        main_layout = new QGridLayout;
                        sell_button = new QToolButton;
                        stock_button = new QToolButton;
                        invoices_button = new QToolButton;
                        management_groupbox = new QGroupBox;
                        management_layout = new QGridLayout;
                        products_button = new QToolButton;
                        services_button = new QToolButton;
                        employees_button = new QToolButton;
                        suppliers_button = new QToolButton;
                        customers_button = new QToolButton;
                        settings_button = new QToolButton;
                        help_button = new QToolButton;
                    }
                    
                    void MainWindow::create_layouts()
                    {
                        create_main_layout();
                        create_management_layout();
                    }
                    
                    void MainWindow::create_main_layout()
                    {
                        main_layout->addWidget(sell_button,0,0,2,2);
                        main_layout->addWidget(stock_button,0,2,2,2);
                        main_layout->addWidget(invoices_button,0,4,2,2);
                        main_layout->addWidget(management_groupbox,2,0,1,6);
                        main_layout->addWidget(settings_button,4,4,1,1);
                        main_layout->addWidget(help_button,4,5,1,1);
                    }
                    
                    void MainWindow::create_management_layout()
                    {
                        management_layout->addWidget(products_button,0,0,1,1);
                        management_layout->addWidget(services_button,0,1,1,1);
                        //Need separator here
                        management_layout->addWidget(employees_button,1,0,1,1);
                        management_layout->addWidget(suppliers_button,1,1,1,1);
                        management_layout->addWidget(customers_button,1,2,1,1);
                    }
                    
                    void MainWindow::create_management_groupbox()
                    {
                        management_groupbox->setTitle("Gestion");
                        management_groupbox->setLayout(management_layout);
                        management_groupbox->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_buttons()
                    {
                        create_sell_button();
                        create_stock_button();
                        create_invoices_button();
                        create_products_button();
                        create_services_button();
                        create_employees_button();
                        create_suppliers_button();
                        create_customers_button();
                        create_settings_button();
                        create_help_button();
                    }
                    
                    void MainWindow::create_sell_button()
                    {
                        sell_button->setIcon(QIcon("Pictures/Sell.png"));
                        sell_button->setIconSize(QSize(96, 96));
                        sell_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        sell_button->setText("Vente");
                        sell_button->setToolTip("Interface de vente");
                        sell_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_stock_button()
                    {
                        stock_button->setIcon(QIcon("Pictures/Stock.png"));
                        stock_button->setIconSize(QSize(96, 96));
                        stock_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        stock_button->setText("Stock");
                        stock_button->setToolTip("Gestion des stocks");
                        stock_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_invoices_button()
                    {
                        invoices_button->setIcon(QIcon("Pictures/Invoices.png"));
                        invoices_button->setIconSize(QSize(96, 96));
                        invoices_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        invoices_button->setText("Factures");
                        invoices_button->setToolTip("Consulter des factures");
                        invoices_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_products_button()
                    {
                        products_button->setIcon(QIcon("Pictures/Products.png"));
                        products_button->setIconSize(QSize(96, 96));
                        products_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        products_button->setText("Articles");
                        products_button->setToolTip("Gestions des produits");
                        products_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_services_button()
                    {
                        services_button->setIcon(QIcon("Pictures/Services.png"));
                        services_button->setIconSize(QSize(96, 96));
                        services_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        services_button->setText("Services");
                        services_button->setToolTip("Gestion des services");
                        services_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_employees_button()
                    {
                        employees_button->setIcon(QIcon("Pictures/Employees.png"));
                        employees_button->setIconSize(QSize(96, 96));
                        employees_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        employees_button->setText("Employés");
                        employees_button->setToolTip("Gestion des employés");
                        employees_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_suppliers_button()
                    {
                        suppliers_button->setIcon(QIcon("Pictures/Suppliers.png"));
                        suppliers_button->setIconSize(QSize(96, 96));
                        suppliers_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        suppliers_button->setText("Fournisseurs");
                        suppliers_button->setToolTip("Gestion des fournisseurs");
                        suppliers_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_customers_button()
                    {
                        customers_button->setIcon(QIcon("Pictures/Customers.png"));
                        customers_button->setIconSize(QSize(96, 96));
                        customers_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        customers_button->setText("Clients");
                        customers_button->setToolTip("Gestion des clients");
                        customers_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_settings_button()
                    {
                        settings_button->setIcon(QIcon("Pictures/Settings.png"));
                        settings_button->setIconSize(QSize(96, 96));
                        settings_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        settings_button->setText("Paramètres");
                        settings_button->setToolTip("Paramètres du logiciel");
                        settings_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    void MainWindow::create_help_button()
                    {
                        help_button->setIcon(QIcon("Pictures/Help.png"));
                        help_button->setIconSize(QSize(96, 96));
                        help_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                        help_button->setText("Aide");
                        help_button->setToolTip("Centre d'aide");
                        help_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                    }
                    
                    

                    Is it possible the problem come because i don't use Layout for the last two buttons at the bottom?

                    Pl45m4P 1 Reply Last reply
                    0
                    • F Fulgurance

                      Yes like this, but just i would like the last two buttons are more small.

                      I have set to minimum expanding, but this don't change bug.

                      It's strange, i have tested, the 3 first buttons have good size when i don't put the 2 last buttons...

                      Look my code (i have just changed QPushButton to QToolButton for somes options):

                      #include "mainwindow.h"
                      
                      MainWindow::MainWindow() : QWidget()
                      {
                          initialize();
                          create_buttons();
                          create_layouts();
                          create_management_groupbox();
                      }
                      
                      void MainWindow::initialize()
                      {
                          setWindowTitle("Caisse");
                          //setWindowIcon(QIcon(""));
                          setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint);
                          initialize_pointers();
                          setLayout(main_layout);
                      }
                      
                      void MainWindow::initialize_pointers()
                      {
                          main_layout = new QGridLayout;
                          sell_button = new QToolButton;
                          stock_button = new QToolButton;
                          invoices_button = new QToolButton;
                          management_groupbox = new QGroupBox;
                          management_layout = new QGridLayout;
                          products_button = new QToolButton;
                          services_button = new QToolButton;
                          employees_button = new QToolButton;
                          suppliers_button = new QToolButton;
                          customers_button = new QToolButton;
                          settings_button = new QToolButton;
                          help_button = new QToolButton;
                      }
                      
                      void MainWindow::create_layouts()
                      {
                          create_main_layout();
                          create_management_layout();
                      }
                      
                      void MainWindow::create_main_layout()
                      {
                          main_layout->addWidget(sell_button,0,0,2,2);
                          main_layout->addWidget(stock_button,0,2,2,2);
                          main_layout->addWidget(invoices_button,0,4,2,2);
                          main_layout->addWidget(management_groupbox,2,0,1,6);
                          main_layout->addWidget(settings_button,4,4,1,1);
                          main_layout->addWidget(help_button,4,5,1,1);
                      }
                      
                      void MainWindow::create_management_layout()
                      {
                          management_layout->addWidget(products_button,0,0,1,1);
                          management_layout->addWidget(services_button,0,1,1,1);
                          //Need separator here
                          management_layout->addWidget(employees_button,1,0,1,1);
                          management_layout->addWidget(suppliers_button,1,1,1,1);
                          management_layout->addWidget(customers_button,1,2,1,1);
                      }
                      
                      void MainWindow::create_management_groupbox()
                      {
                          management_groupbox->setTitle("Gestion");
                          management_groupbox->setLayout(management_layout);
                          management_groupbox->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_buttons()
                      {
                          create_sell_button();
                          create_stock_button();
                          create_invoices_button();
                          create_products_button();
                          create_services_button();
                          create_employees_button();
                          create_suppliers_button();
                          create_customers_button();
                          create_settings_button();
                          create_help_button();
                      }
                      
                      void MainWindow::create_sell_button()
                      {
                          sell_button->setIcon(QIcon("Pictures/Sell.png"));
                          sell_button->setIconSize(QSize(96, 96));
                          sell_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          sell_button->setText("Vente");
                          sell_button->setToolTip("Interface de vente");
                          sell_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_stock_button()
                      {
                          stock_button->setIcon(QIcon("Pictures/Stock.png"));
                          stock_button->setIconSize(QSize(96, 96));
                          stock_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          stock_button->setText("Stock");
                          stock_button->setToolTip("Gestion des stocks");
                          stock_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_invoices_button()
                      {
                          invoices_button->setIcon(QIcon("Pictures/Invoices.png"));
                          invoices_button->setIconSize(QSize(96, 96));
                          invoices_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          invoices_button->setText("Factures");
                          invoices_button->setToolTip("Consulter des factures");
                          invoices_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_products_button()
                      {
                          products_button->setIcon(QIcon("Pictures/Products.png"));
                          products_button->setIconSize(QSize(96, 96));
                          products_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          products_button->setText("Articles");
                          products_button->setToolTip("Gestions des produits");
                          products_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_services_button()
                      {
                          services_button->setIcon(QIcon("Pictures/Services.png"));
                          services_button->setIconSize(QSize(96, 96));
                          services_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          services_button->setText("Services");
                          services_button->setToolTip("Gestion des services");
                          services_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_employees_button()
                      {
                          employees_button->setIcon(QIcon("Pictures/Employees.png"));
                          employees_button->setIconSize(QSize(96, 96));
                          employees_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          employees_button->setText("Employés");
                          employees_button->setToolTip("Gestion des employés");
                          employees_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_suppliers_button()
                      {
                          suppliers_button->setIcon(QIcon("Pictures/Suppliers.png"));
                          suppliers_button->setIconSize(QSize(96, 96));
                          suppliers_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          suppliers_button->setText("Fournisseurs");
                          suppliers_button->setToolTip("Gestion des fournisseurs");
                          suppliers_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_customers_button()
                      {
                          customers_button->setIcon(QIcon("Pictures/Customers.png"));
                          customers_button->setIconSize(QSize(96, 96));
                          customers_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          customers_button->setText("Clients");
                          customers_button->setToolTip("Gestion des clients");
                          customers_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_settings_button()
                      {
                          settings_button->setIcon(QIcon("Pictures/Settings.png"));
                          settings_button->setIconSize(QSize(96, 96));
                          settings_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          settings_button->setText("Paramètres");
                          settings_button->setToolTip("Paramètres du logiciel");
                          settings_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      void MainWindow::create_help_button()
                      {
                          help_button->setIcon(QIcon("Pictures/Help.png"));
                          help_button->setIconSize(QSize(96, 96));
                          help_button->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
                          help_button->setText("Aide");
                          help_button->setToolTip("Centre d'aide");
                          help_button->setSizePolicy(QSizePolicy::Expanding , QSizePolicy::Expanding);
                      }
                      
                      

                      Is it possible the problem come because i don't use Layout for the last two buttons at the bottom?

                      Pl45m4P Offline
                      Pl45m4P Offline
                      Pl45m4
                      wrote on last edited by Pl45m4
                      #10

                      @Fulgurance said in Problem with somes QPushButton size:

                      i would like the last two buttons are more small

                      You can set the layoutStretch of the mainLayout (VBoxLayout in my case) to e.g. 4, 4, 1
                      First 4 for the top three buttons, second 4 for GroupBox and 1 for your last, bottom HBoxLayout, which includes your 2 Buttons.
                      It means, that the available space is devided into 9 parts... The two top layouts take 8/9 (both 4) and the bottom layout is 1/4 of each of them ( 4/9, 4/9, 1/9).

                      @Fulgurance said in Problem with somes QPushButton size:

                      i don't use Layout for the last two buttons at the bottom

                      Better use layouts. Dont let your buttons floating around


                      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                      ~E. W. Dijkstra

                      1 Reply Last reply
                      2
                      • F Offline
                        F Offline
                        Fulgurance
                        wrote on last edited by
                        #11

                        It's good when i split into 9, without layout. Just one last little question. When my application start, the first button is selected automatically. How can i disable that ?
                        I have tested setFocusPolicy(Qt::NoFocus), but this donc work

                        Pl45m4P 1 Reply Last reply
                        0
                        • F Fulgurance

                          It's good when i split into 9, without layout. Just one last little question. When my application start, the first button is selected automatically. How can i disable that ?
                          I have tested setFocusPolicy(Qt::NoFocus), but this donc work

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by Pl45m4
                          #12

                          @Fulgurance said in Problem with somes QPushButton size:

                          the first button is selected automatically

                          You mean, when you press Enter / Space, you activate the button?!
                          Set default to false.
                          https://doc.qt.io/qt-5/qpushbutton.html#default-prop

                          EDIT:

                          Ah.... this wont solve your problem, because

                          If the default property is set to false on the current default button while the dialog is visible, a new default will automatically be assigned the next time a push button in the dialog receives focus.


                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          1 Reply Last reply
                          0
                          • F Offline
                            F Offline
                            Fulgurance
                            wrote on last edited by Fulgurance
                            #13

                            If i understand good your sentence, i need to change the default focus policy for QPushButton?

                            Edit: It's good, i have understood, thanks you !

                            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