Results 1 to 7 of 7

Thread: QMainWindows show empty QWidget

  1. #1
    Join Date
    Jul 2016
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QMainWindows show empty QWidget

    Hi, I've a little problem, this is my code.

    mainmindow.h

    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5. #include <QLabel>
    6.  
    7. //class MdiChild;
    8. class QLabel;
    9. class QMenu;
    10. class QAction;
    11. class QMdiArea;
    12. class FrmMantenimientoSexo;
    13.  
    14. class MainWindow : public QMainWindow
    15. {
    16. Q_OBJECT
    17.  
    18. public:
    19. explicit MainWindow(const QString smwUserName/*, QWidget *parent = 0*/);
    20. ~MainWindow();
    21. void setUserName(QString smwUserName);
    22. QString getUserName();
    23.  
    24. private:
    25. QMdiArea *mdiArea;
    26. QString sUserName;
    27. QMenu *mnProceso;
    28. QMenu *mnMantenimiento;
    29. QMenu *mnTablas;
    30. QMenu *mnAyuda;
    31. QAction *acRegistro;
    32. QAction *acSalir;
    33. QAction *acTablaEstadoCivil;
    34. QAction *acTablaSexo;
    35. QAction *acFirstRecord;
    36. QAction *acPreviousRecord;
    37. QAction *acNextRecord;
    38. QAction *acLastRecord;
    39. QAction *acAcercaDe;
    40. QToolBar *tbProceso;
    41. QToolBar *tbIrA;
    42. QLabel *lbStatus;
    43. FrmMantenimientoSexo *wlffrmSexo;
    44. void createMenus();
    45. void createActions();
    46. void createToolBar();
    47. void createStatusBar();
    48. bool okToContinue();
    49.  
    50. private slots:
    51. void mantenimientoTablaEstadoCivil();
    52. void mantenimientoTablaSexo();
    53. void enableToolBar();
    54. FrmMantenimientoSexo *createFrmMantenimientoSexo();
    55.  
    56.  
    57. protected:
    58. void closeEvent(QCloseEvent *ceMainWindow);
    59.  
    60. signals:
    61. };
    62.  
    63. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainmindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QMenu>
    3. #include <QMenuBar>
    4. #include <QToolBar>
    5. #include <QStatusBar>
    6. #include <QMessageBox>
    7. #include <QtGui>
    8. #include <QMdiArea>
    9. #include <QMdiSubWindow>
    10. #include "frmmantenimientosexo.h"
    11. #include "vwmantenimientosexo.h"
    12.  
    13.  
    14. MainWindow::MainWindow(const QString smwUserName/*, QWidget *parent*/)// : QMainWindow(parent)
    15. {
    16. mdiArea = new QMdiArea;
    17. setCentralWidget(mdiArea);
    18.  
    19. setUserName(smwUserName);
    20. setWindowTitle("JMadi: Sistema Integral [USUARIO: " + smwUserName + "]");
    21. createActions();
    22. createMenus();
    23. createToolBar();
    24. createStatusBar();
    25. setMinimumSize(1024,768);
    26. setAttribute(Qt::WA_DeleteOnClose);
    27. }
    28.  
    29. void MainWindow::mantenimientoTablaSexo()
    30. {
    31. tbIrA->setEnabled(true);
    32. wlffrmSexo = createFrmMantenimientoSexo();
    33. wlffrmSexo->show();
    34. }
    35.  
    36. FrmMantenimientoSexo *MainWindow::createFrmMantenimientoSexo()
    37. {
    38. QString strTable = "cp21021976.tb_sexo";
    39.  
    40. wlffrmSexo = new FrmMantenimientoSexo(getUserName(), strTable);
    41. mdiArea->addSubWindow(wlffrmSexo);
    42.  
    43. return wlffrmSexo;
    44. }
    To copy to clipboard, switch view to plain text mode 

    when the program run, I get:
    Screenshot from 2016-07-21 12:52:28.jpg

    why the widget is empty? can you help me please?
    Last edited by anda_skoa; 21st July 2016 at 21:18. Reason: changed [quote] to [code]

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindows show empty QWidget

    If you mean "why is the sub window empty?", then you forgot to post the code for "FrmMantenimientoSexo"

    Cheers,
    _

  3. #3
    Join Date
    Jul 2016
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMainWindows show empty QWidget

    I'm sorry, this is frmmantenimiento.h

    Qt Code:
    1. #ifndef FRMMANTENIMIENTOSEXO_H
    2. #define FRMMANTENIMIENTOSEXO_H
    3.  
    4. #include <QWidget>
    5. #include <QDialog>
    6. #include <QSqlQuery>
    7. #include <QMdiSubWindow>
    8.  
    9. class QLabel;
    10. class QLineEdit;
    11.  
    12. class FrmMantenimientoSexo : public QWidget
    13. {
    14. Q_OBJECT
    15. public:
    16. explicit FrmMantenimientoSexo(const QString strUserName, const QString strTableName, QWidget *parent = 0);
    17. void enableInput();
    18. void disableInput();
    19.  
    20. private:
    21. QLabel *lbCodigo;
    22. QLineEdit *leCodigo;
    23. QLabel *lbDescripcion;
    24. QLineEdit *leDescripcion;
    25. QGridLayout *glInput;
    26. QString strUserName;
    27. QString strTableName;
    28.  
    29. protected:
    30. void closeEvent(QCloseEvent *ceFrmMantenimientoSexo);
    31.  
    32. signals:
    33. void closeFormSexo();
    34. };
    35.  
    36. #endif // FRMMANTENIMIENTOSEXO_H
    To copy to clipboard, switch view to plain text mode 

    and this is frmmantenimiento.cpp
    Qt Code:
    1. #include "frmmantenimientosexo.h"
    2. #include "connectdb.h"
    3. #include <QLabel>
    4. #include <QLineEdit>
    5. #include <QGridLayout>
    6. #include <QSqlQuery>
    7. #include <QCloseEvent>
    8.  
    9. #include <QDebug>
    10.  
    11. FrmMantenimientoSexo::FrmMantenimientoSexo(const QString strUserName, const QString strTableName, QWidget *parent) : QWidget(parent)
    12. {
    13. this->strUserName = strUserName;
    14. this->strTableName = strTableName;
    15.  
    16. lbCodigo = new QLabel(tr("Código"));
    17. leCodigo = new QLineEdit;
    18. leCodigo->setFixedWidth(30);
    19.  
    20. lbDescripcion = new QLabel(tr("Descripción"));
    21. leDescripcion = new QLineEdit;
    22. leDescripcion->setFixedWidth(150);
    23.  
    24. glInput = new QGridLayout;
    25. glInput->addWidget(lbCodigo, 0, 0);
    26. glInput->addWidget(leCodigo, 0, 1);
    27. glInput->addWidget(lbDescripcion, 1, 0);
    28. glInput->addWidget(leDescripcion, 1, 1);
    29.  
    30. this->setLayout(glInput);
    31. this->setWindowTitle("Mantenimiento: TABLA[" + strTableName + "]" + " " + "USUARIO[" + strUserName + "]");
    32. this->setFixedSize(minimumWidth(), minimumHeight());
    33.  
    34. disableInput();
    35.  
    36. this->setAttribute(Qt::WA_DeleteOnClose);
    37. }
    38.  
    39. void FrmMantenimientoSexo::enableInput()
    40. {
    41. leCodigo->setEnabled(true);
    42. leDescripcion->setEnabled(true);
    43. }
    44.  
    45. void FrmMantenimientoSexo::disableInput()
    46. {
    47. leCodigo->setEnabled(false);
    48. leDescripcion->setEnabled(false);
    49. }
    50.  
    51. void FrmMantenimientoSexo::closeEvent(QCloseEvent *ceFrmMantenimientoSexo)
    52. {
    53. emit closeFormSexo();
    54. ceFrmMantenimientoSexo->accept();
    55. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindows show empty QWidget

    Don't do things like setFixedWidth/Height/Size.

    Let the layout do its job

    Cheers,
    _

  5. #5
    Join Date
    Jul 2016
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMainWindows show empty QWidget

    anda_skoa, you're amazing, thanks... an additional thing, i just want only close button on frmmantenimiento, how i do it?

  6. #6
    Join Date
    Jul 2016
    Posts
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMainWindows show empty QWidget

    How do I remove max and min buttons in frmmantenimientosexo?


    Qt Code:
    1. FrmMantenimientoSexo::FrmMantenimientoSexo(const QString strUserName, const QString strTableName, QWidget *parent) : QWidget(parent)
    2. {
    3. .
    4. .
    5. .
    6.  
    7. this->setWindowFlags(Qt::WindowMinimizeButtonHint | Qt::WindowMinimizeButtonHint);
    To copy to clipboard, switch view to plain text mode 

    that's not work.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindows show empty QWidget

    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,
    _

Similar Threads

  1. How to show MS Word int QWidget ?
    By luoyes in forum Qt Programming
    Replies: 8
    Last Post: 3rd December 2013, 04:22
  2. QWidget.show () is slow
    By rdf in forum Qt Programming
    Replies: 6
    Last Post: 7th December 2012, 15:04
  3. QTreeView - force to show expand arrows on empty folders
    By cierpliwy in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2012, 01:09
  4. Replies: 5
    Last Post: 29th June 2010, 11:58
  5. QWidget::exec() and QWidget::show()
    By MarkoSan in forum Qt Programming
    Replies: 6
    Last Post: 18th October 2007, 21:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.