Cómo deshabilitar los botones del Form: Maximizar, Minimizar y Close.
-
Hola soy nuevo en QT
Estoy haciendo una aplicación en QT (Qt Widgets Application)
Y me gustaría ocultar los botones de minimizar, maximizar y cerrar del form. He leído algo y la info me apunta que lo puede hacer con el siguiente comando (setWindowFlags(Qt::WindowCloseButtonHint);
setWindowFlags(Qt::WindowMaximizeButtonHint);
setWindowFlags(Qt::WindowMinimizeButtonHint);) , pero no se en que parte del código se debe colocar para que funcione o si tengo que referirlo a Formulario, he probado en varias partes y siempre me da error, agradecería si me pueden orientar. -
Hola @Heyner-AO
Eso tienes que aplicárselo a la ventana que quieras ocultar los botones, es un método de la clase QWidget, por ejemplo:
MainWindow w; w.setWindowFlags(Qt::WindowCloseButtonHint);
Un saludo
-
@Heyner-AO
Esto es lo que hecho de código
Interface.h
#ifndef INTERFACE_H
#define INTERFACE_H
#include <QMainWindow>
namespace Ui {
class Interface;
}
class Interface : public QMainWindow
{
Q_OBJECT
public:
explicit Interface(QWidget *parent = 0);
~Interface();
private slots:
void on_ON_VIB_2_clicked(); void on_VIB_ALL_clicked(); void on_ON_VIB_3_clicked(); void on_ON_VIB_4_clicked(); void on_Cerrar_VIB_clicked();
private:
Ui::Interface *ui; };
#endif // INTERFACE_H
interface.cpp
#include "interface.h"
#include "ui_interface.h"
bool STATUS_VIB[4] = {false,false,false,false}; //variable global de vib
Interface::Interface(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::Interface)
{
ui->setupUi(this); ui->Mensaje->setHidden(true); ui->ON_VIB_2->setStyleSheet("background-color: red"); ui->ON_VIB_3->setStyleSheet("background-color: red"); ui->ON_VIB_4->setStyleSheet("background-color: red");
}
Interface::~Interface()
{
delete ui;
}
void Interface::on_ON_VIB_2_clicked()
{
if(STATUS_VIB[0] == false) {
ui->ON_VIB_2->setStyleSheet("background-color: green"); STATUS_VIB[0]= true;}else {ui->ON_VIB_2->setStyleSheet("background-color: red"); STATUS_VIB[0]= false;}
}
void Interface::on_ON_VIB_3_clicked()
{
if(STATUS_VIB[1] == false) {
ui->ON_VIB_3->setStyleSheet("background-color: green"); STATUS_VIB[1]= true;}else {ui->ON_VIB_3->setStyleSheet("background-color: red"); STATUS_VIB[1]= false;}
}
main.cpp
#include "interface.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv); Interface w; w.show(); return a.exec();
}
-
Hola @Heyner-AO
Puedes ponerlo en varios lugares, por ejemplo en el main, donde creas la ventanan:
QApplication a(argc, argv); Interface w; w.setWindowFlags(Qt::WindowCloseButtonHint); w.show();
O en el constructor de la clase Interface. Y también podrías crear un método dentro de la clase Interface. Cuestión de gustos, personalmente lo hago como te puse en el ejemplo, aunque tampoco me disgusta la opción de ponerlo en el constructor.
Un saludo
-
Tienes que ponerte las pilas con C++ @Heyner-AO , esto que hemos hecho aquí es muy básico y son cosas que no pueden hacerte perder el tiempo.
Coge un curso de C++ de los muchos que hay por internet y ve dándole un vistazo para que te aclaren los conceptos.
Por cierto, si se solucionó tu duda, marca el tema como solucionado :)
Un saludo