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. Controls visibility.
Forum Updated to NodeBB v4.3 + New Features

Controls visibility.

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 1.7k 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.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by
    #1

    Good afternoon, I have a simple question, I have a MainWindow where I have a file menu within a sub menu open when you click on this one unfold QDialog, where I have a button that just closes the dialog.
    my question is how to disable the submenu to open the MainWindow, from QDialog, after closing it.

    I hope you can help me, any suggestions would appreciate it ...
    Greetings.

    Solitary wolf

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andreyc
      wrote on last edited by
      #2

      Could you please show how do you implement open and close of QDialog.

      And where do you need to disable a sub-menu? In MainWindow or in QDialog.

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        qxoz
        wrote on last edited by
        #3

        First thing comes to mind is signal and slot mechanism, but i didn't understand your goals too. If you explain more we can give more useful advices.

        1 Reply Last reply
        0
        • lincolnL Offline
          lincolnL Offline
          lincoln
          wrote on last edited by
          #4

          I found this on the net, and I have managed to disable the menu of the mainwindow, from QDialog.

          in the click event of the button of QDialog:
          @static_cast<MainWindow*> (parent ()) -> activarMenu ();
           accept (); @

          activarMenu (), is a public method that is in the mainwindows, all alone I send call from QDialog. my question is whether it is right to do that.

          this is the code mainwindow.h

          @#ifndef MAINWINDOW_H
          #define MAINWINDOW_H
          #include <QMainWindow>
          #include "frmlogin.h"
          namespace Ui {
          class MainWindow;
          }

          class MainWindow : public QMainWindow
          {
          Q_OBJECT

          public:
          explicit MainWindow(QWidget *parent = 0);
          ~MainWindow();

          private slots:
          void on_actionIniciar_sesion_triggered();
          private:
          Ui::MainWindow *ui;
          frmLogin *login;
          public:
          void activarMenu();
          };

          #endif // MAINWINDOW_H@

          this is the code mainwindow.cpp:

          @#include "mainwindow.h"
          #include "ui_mainwindow.h"
          MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow){
          ui->setupUi(this);
          }

          MainWindow::~MainWindow(){
          delete ui;
          }

          void MainWindow::on_actionIniciar_sesion_triggered(){
          login=new frmLogin(this);
          login->setFixedSize(341,106);
          login->exec();
          }
          void MainWindow::activarMenu(){
          ui->actionIniciar_sesion->setEnabled(false);

          }@

          this is the code frmlogin.h:

          @#ifndef FRMLOGIN_H
          #define FRMLOGIN_H
          #include <QDialog>
          namespace Ui {
          class frmLogin;
          }
          class frmLogin : public QDialog{
          Q_OBJECT

          public:
          explicit frmLogin(QWidget *parent = 0);
          ~frmLogin();

          protected slots:
          void on_pushButton_clicked();
          };

          #endif // FRMLOGIN_H@

          this the code frmlogin.cpp

          @#include "frmlogin.h"
          #include "ui_frmlogin.h"
          #include <QMessageBox>
          #include "mainwindow.h"
          frmLogin::frmLogin(QWidget *parent) : QDialog(parent),ui(new Ui::frmLogin){
          ui->setupUi(this);
          ui->Password->setEchoMode(QLineEdit::Password);
          }

          frmLogin::~frmLogin(){
          delete ui;
          }
          void frmLogin::on_pushButton_clicked(){
          if(ui->Usuario->text()=="lincoln"&&ui->Password->text()=="miclave"){
          static_cast<MainWindow*>(parent())->activarMenu();
          accept();
          }
          }
          @

          Solitary wolf

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi,

            That's completely unclean. static_cast doesn't make any check so you may be casting to the wrong class.

            And since you are calling that login dialog from MainWindow you should just check whether the return value of exec is accepted or rejected and enable/disable the menu based on that. frmDialog doesn't need to know anything about the MainWindow, it's not it's job.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • lincolnL Offline
              lincolnL Offline
              lincoln
              wrote on last edited by
              #6

              then that would make the job so, what is the best way?

              Solitary wolf

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                It's there:

                [quote author="SGaist" date="1400572157"]
                And since you are calling that login dialog from MainWindow you should just check whether the return value of exec is accepted or rejected and enable/disable the menu based on that. [/quote]

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0

                • Login

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