PDA

View Full Version : QMainWindows show empty QWidget



Tarko1976
21st July 2016, 19:04
Hi, I've a little problem, this is my code.

mainmindow.h



#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QLabel>

//class MdiChild;
class QLabel;
class QMenu;
class QAction;
class QMdiArea;
class FrmMantenimientoSexo;

class MainWindow : public QMainWindow
{
Q_OBJECT

public:
explicit MainWindow(const QString smwUserName/*, QWidget *parent = 0*/);
~MainWindow();
void setUserName(QString smwUserName);
QString getUserName();

private:
QMdiArea *mdiArea;
QString sUserName;
QMenu *mnProceso;
QMenu *mnMantenimiento;
QMenu *mnTablas;
QMenu *mnAyuda;
QAction *acRegistro;
QAction *acSalir;
QAction *acTablaEstadoCivil;
QAction *acTablaSexo;
QAction *acFirstRecord;
QAction *acPreviousRecord;
QAction *acNextRecord;
QAction *acLastRecord;
QAction *acAcercaDe;
QToolBar *tbProceso;
QToolBar *tbIrA;
QLabel *lbStatus;
FrmMantenimientoSexo *wlffrmSexo;
void createMenus();
void createActions();
void createToolBar();
void createStatusBar();
bool okToContinue();

private slots:
void mantenimientoTablaEstadoCivil();
void mantenimientoTablaSexo();
void enableToolBar();
FrmMantenimientoSexo *createFrmMantenimientoSexo();


protected:
void closeEvent(QCloseEvent *ceMainWindow);

signals:
};

#endif // MAINWINDOW_H


mainmindow.cpp


#include "mainwindow.h"
#include <QMenu>
#include <QMenuBar>
#include <QToolBar>
#include <QStatusBar>
#include <QMessageBox>
#include <QtGui>
#include <QMdiArea>
#include <QMdiSubWindow>
#include "frmmantenimientosexo.h"
#include "vwmantenimientosexo.h"


MainWindow::MainWindow(const QString smwUserName/*, QWidget *parent*/)// : QMainWindow(parent)
{
mdiArea = new QMdiArea;
setCentralWidget(mdiArea);

setUserName(smwUserName);
setWindowTitle("JMadi: Sistema Integral [USUARIO: " + smwUserName + "]");
createActions();
createMenus();
createToolBar();
createStatusBar();
setMinimumSize(1024,768);
setAttribute(Qt::WA_DeleteOnClose);
}

void MainWindow::mantenimientoTablaSexo()
{
tbIrA->setEnabled(true);
wlffrmSexo = createFrmMantenimientoSexo();
wlffrmSexo->show();
}

FrmMantenimientoSexo *MainWindow::createFrmMantenimientoSexo()
{
QString strTable = "cp21021976.tb_sexo";

wlffrmSexo = new FrmMantenimientoSexo(getUserName(), strTable);
mdiArea->addSubWindow(wlffrmSexo);

return wlffrmSexo;
}


when the program run, I get:
12038

why the widget is empty? can you help me please?

anda_skoa
21st July 2016, 21:21
If you mean "why is the sub window empty?", then you forgot to post the code for "FrmMantenimientoSexo"

Cheers,
_

Tarko1976
22nd July 2016, 00:20
I'm sorry, this is frmmantenimiento.h



#ifndef FRMMANTENIMIENTOSEXO_H
#define FRMMANTENIMIENTOSEXO_H

#include <QWidget>
#include <QDialog>
#include <QSqlQuery>
#include <QMdiSubWindow>

class QLabel;
class QLineEdit;
class QPushButton;
class QHBoxLayout;
class QVBoxLayout;
class QGridLayout;

class FrmMantenimientoSexo : public QWidget
{
Q_OBJECT
public:
explicit FrmMantenimientoSexo(const QString strUserName, const QString strTableName, QWidget *parent = 0);
void enableInput();
void disableInput();

private:
QLabel *lbCodigo;
QLineEdit *leCodigo;
QLabel *lbDescripcion;
QLineEdit *leDescripcion;
QGridLayout *glInput;
QString strUserName;
QString strTableName;

protected:
void closeEvent(QCloseEvent *ceFrmMantenimientoSexo);

signals:
void closeFormSexo();
};

#endif // FRMMANTENIMIENTOSEXO_H



and this is frmmantenimiento.cpp


#include "frmmantenimientosexo.h"
#include "connectdb.h"
#include <QLabel>
#include <QLineEdit>
#include <QGridLayout>
#include <QSqlQuery>
#include <QCloseEvent>

#include <QDebug>

FrmMantenimientoSexo::FrmMantenimientoSexo(const QString strUserName, const QString strTableName, QWidget *parent) : QWidget(parent)
{
this->strUserName = strUserName;
this->strTableName = strTableName;

lbCodigo = new QLabel(tr("Código"));
leCodigo = new QLineEdit;
leCodigo->setFixedWidth(30);

lbDescripcion = new QLabel(tr("Descripción"));
leDescripcion = new QLineEdit;
leDescripcion->setFixedWidth(150);

glInput = new QGridLayout;
glInput->addWidget(lbCodigo, 0, 0);
glInput->addWidget(leCodigo, 0, 1);
glInput->addWidget(lbDescripcion, 1, 0);
glInput->addWidget(leDescripcion, 1, 1);

this->setLayout(glInput);
this->setWindowTitle("Mantenimiento: TABLA[" + strTableName + "]" + " " + "USUARIO[" + strUserName + "]");
this->setFixedSize(minimumWidth(), minimumHeight());

disableInput();

this->setAttribute(Qt::WA_DeleteOnClose);
}

void FrmMantenimientoSexo::enableInput()
{
leCodigo->setEnabled(true);
leDescripcion->setEnabled(true);
}

void FrmMantenimientoSexo::disableInput()
{
leCodigo->setEnabled(false);
leDescripcion->setEnabled(false);
}

void FrmMantenimientoSexo::closeEvent(QCloseEvent *ceFrmMantenimientoSexo)
{
emit closeFormSexo();
ceFrmMantenimientoSexo->accept();
}

anda_skoa
22nd July 2016, 01:35
Don't do things like setFixedWidth/Height/Size.

Let the layout do its job :)

Cheers,
_

Tarko1976
22nd July 2016, 02:04
anda_skoa, you're amazing, thanks... an additional thing, i just want only close button on frmmantenimiento, how i do it?

Tarko1976
22nd July 2016, 07:02
How do I remove max and min buttons in frmmantenimientosexo?




FrmMantenimientoSexo::FrmMantenimientoSexo(const QString strUserName, const QString strTableName, QWidget *parent) : QWidget(parent)
{
.
.
.

this->setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinimizeButtonHint);


that's not work.

anda_skoa
22nd July 2016, 10:44
FrmMantenimientoSexo is the content of the sub window, not the sub window itself.

Try setting flags on the sub window that you get back from the QMdiArea.

Cheers,
_