Unsolved Invisible buttons
-
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 -
@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.
-
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 -
@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.