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. Invisible buttons
Qt 6.11 is out! See what's new in the release blog

Invisible buttons

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

    Hello
    I have a window create in Qt designer.
    I inserted two standard buttons "bttoncene and bttoncenep" on the main window in Gridlayout.
    But the buttons are not displayed when I compile.

    The code.h

    #ifndef FENPRINCIPALE_H
    #define FENPRINCIPALE_H
    
    #include <QMainWindow>
    #include <QWidget>
    #include <QStackedWidget>
    #include "fencene.h"
    #include "fencenep.h"
    
    
    namespace Ui {
    class FenPrincipale;
    }
    
    class FenPrincipale : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit FenPrincipale(QWidget *parent = 0);
        ~FenPrincipale();
    
    private:
        Ui::FenPrincipale *ui;
        QStackedWidget *centralfencen;
    
    
    public slots:
        void Affichefencene();
        void Affichefencenep();
    
    };
    
    #endif // FENPRINCIPALE_H
    
    

    The code.cpp

    #include "fenprincipale.h"
    #include "ui_fenprincipale.h"
    #include "fencene.h"
    #include "fencenep.h"
    #include <QStackedWidget>
    
    FenPrincipale::FenPrincipale(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::FenPrincipale)
    {
        ui->setupUi(this);
    
        centralfencen = new QStackedWidget;
        centralfencen ->addWidget(new FenCene);
        centralfencen ->addWidget(new FenCenep);
        setCentralWidget(centralfencen);
    
        connect(ui->bttoncene, &QPushButton::clicked, this, &FenPrincipale::Affichefencene);
        connect(ui->bttoncenep,  &QPushButton::clicked, this, &FenPrincipale::Affichefencenep);
    }
    
    FenPrincipale::~FenPrincipale()
    {
        delete ui;
    }
    
    void FenPrincipale::Affichefencene()
    {
        centralfencen->setCurrentIndex(0);
    }
    
    void FenPrincipale::Affichefencenep()
    {
       centralfencen->setCurrentIndex(1);
    }
    
    

    Where did I make a mistake?
    Thank you in advance

    M 1 Reply Last reply
    0
    • Nafab213N Nafab213

      Hello
      I have a window create in Qt designer.
      I inserted two standard buttons "bttoncene and bttoncenep" on the main window in Gridlayout.
      But the buttons are not displayed when I compile.

      The code.h

      #ifndef FENPRINCIPALE_H
      #define FENPRINCIPALE_H
      
      #include <QMainWindow>
      #include <QWidget>
      #include <QStackedWidget>
      #include "fencene.h"
      #include "fencenep.h"
      
      
      namespace Ui {
      class FenPrincipale;
      }
      
      class FenPrincipale : public QMainWindow
      {
          Q_OBJECT
      
      public:
          explicit FenPrincipale(QWidget *parent = 0);
          ~FenPrincipale();
      
      private:
          Ui::FenPrincipale *ui;
          QStackedWidget *centralfencen;
      
      
      public slots:
          void Affichefencene();
          void Affichefencenep();
      
      };
      
      #endif // FENPRINCIPALE_H
      
      

      The code.cpp

      #include "fenprincipale.h"
      #include "ui_fenprincipale.h"
      #include "fencene.h"
      #include "fencenep.h"
      #include <QStackedWidget>
      
      FenPrincipale::FenPrincipale(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::FenPrincipale)
      {
          ui->setupUi(this);
      
          centralfencen = new QStackedWidget;
          centralfencen ->addWidget(new FenCene);
          centralfencen ->addWidget(new FenCenep);
          setCentralWidget(centralfencen);
      
          connect(ui->bttoncene, &QPushButton::clicked, this, &FenPrincipale::Affichefencene);
          connect(ui->bttoncenep,  &QPushButton::clicked, this, &FenPrincipale::Affichefencenep);
      }
      
      FenPrincipale::~FenPrincipale()
      {
          delete ui;
      }
      
      void FenPrincipale::Affichefencene()
      {
          centralfencen->setCurrentIndex(0);
      }
      
      void FenPrincipale::Affichefencenep()
      {
         centralfencen->setCurrentIndex(1);
      }
      
      

      Where did I make a mistake?
      Thank you in advance

      M Offline
      M Offline
      mpergand
      wrote on last edited by
      #2

      @Nafab213 said in Invisible buttons:

      ui->setupUi(this);
      
      setCentralWidget(centralfencen);
      

      The second line replace what you did in the Designer with centralfencen. (c'est ballot !)

      You have to position the buttons somewhere else (in a Toolbar for ex) or place centralfen in the grid itself.

      1 Reply Last reply
      3
      • Nafab213N Offline
        Nafab213N Offline
        Nafab213
        wrote on last edited by
        #3

        I place the buttons in the toolbar? Or elsewhere ?
        I don't understand..
        I would like to display both buttons on the main window.
        How can I do it? I show them how?
        Thnks

        jsulmJ 1 Reply Last reply
        0
        • Nafab213N Nafab213

          I place the buttons in the toolbar? Or elsewhere ?
          I don't understand..
          I would like to display both buttons on the main window.
          How can I do it? I show them how?
          Thnks

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @Nafab213 As @mpergand said you're replacing central widget with another one. Your buttons are in the central widget, then you create a new widget and set it as new central widget - how can you expect to see the buttons which are placed on a central widget you just replaced? Simply use the central widget you're already using (don't call setCentralWidget) and add centralfencen to the existing layout.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          • Login

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