Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Active window



  • The window is open, but the button that called it does not work. Until the window disappears.


  • Lifetime Qt Champion

    @TETTRA
    can you please show the code ?



  • @mrjj Call:

           //new
            newFile = new QAction (tr("New"),this);
              newFile->setShortcut(QKeySequence::New);
              connect(newFile,&QAction::triggered,this, &MainWindow::newfile);
              file->addAction(newFile);
    

    slot:

    void MainWindow::newfile(){
        newF *newf = new newF();
        newf->show();
    }
    

  • Lifetime Qt Champion

    looks fine

    So MainWindow::newfile is called ?

    but newF is not shown or ?



  • @mrjj Everything works. Just tell me how to do it the way I asked? if you know


  • Lifetime Qt Champion

    @TETTRA
    I really dont understand what u ask, else i would tell you.

    void MainWindow::newfile() does nothing but showing the dialog so i dont understand your sentence

    "the window is open, but the button that called it does not work. Until the window disappears."

    But its not a button that calls it, its the QAction

    So i do not know what is not working.



  • @mrjj In various programs there is a button that creates a new window in which you can for example draw and when creating this window a window appears that requests additional parameters (name, etc.) and that these windows would not have much, the button that called this window Is turned off. Like this.


  • Lifetime Qt Champion

    @TETTRA said in Active window:

    the button that called this window Is turned off

    What you mean ? Like if u click it once, the window open. And the button is grey so u cant click on it again?
    (before windows is closed ?)
    is it to prevent to get multiple windows if u click many times on the button?



  • @mrjj said in Active window:

    What you mean ? Like if u click it once, the window open. And the button is grey so u cant click on it again?
    (before windows is closed ?)
    is it to prevent to get multiple windows if u click many times on the button?

    Yes


  • Lifetime Qt Champion

    @TETTRA
    You can use
    button->setEnabled(false);
    when you open dialog.

    You must then catch when dialog closes and set button back to active.



  • @mrjj

    I tried, but I did not succeed, you can write.


  • Lifetime Qt Champion

    @TETTRA
    What part did not work?

    Here is sample using QDialog and a custom signal.
    https://www.dropbox.com/s/7sjc6yz3zne395v/floatingdialog.zip?dl=0



  • @mrjj I'm sorru buet i really don't understand.

    #include "newf.h"
    #include "ui_newf.h"
    #include <QWidget>
    #include <QHBoxLayout>
    #include <QVBoxLayout>
    #include <QPushButton>
    
    #include "mainwindow.h"
    #include "stylehelper.h"
    #include "projectwindow.h"
    
    newF::newF(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::newF)
    {
        ui->setupUi(this);
    
        this->setWindowFlags(Qt::SplashScreen);
        this->setStyleSheet("QDialog {"
                            "background-color: #363636;"
                            "color: #FFFFFF;"
                            "}"
                            "QDialog::item:selected {"
                            "background-color: #6B6B6B"
                            "}");
    
        txt = new QLabel("New...",this);
        txt->setGeometry(4, 4, 50, 10);
        txt->setStyleSheet("QLabel {"
                           "color: #FFFFFF;"
                           "}");
    
        QPushButton *close = new QPushButton (this);
        close->setGeometry(189, 1, 40, 18);
        close->setStyleSheet("QPushButton {"
                             "image: url(:/images/close.png);"
                             "background-color: #000000;"
                             "border: none;"
                             "}"
                             "QPushButton:hover {"
                             "background-color: red; "
                             "}");
        connect(close,SIGNAL(clicked()),this,SLOT(close()));
    
        newf = new QLabel("Name:",this);
        newf->setStyleSheet("QLabel {"
                            "background-color: #363636;"
                            "color: #000000;"
                            "}");
        name = new QLineEdit(this);
        name->text();
        name->setMaxLength(40);
        name->setStyleSheet("QLineEdit {"
                            "color: #000000;"
                            "background-color: #696969;"
                            "border: 1px double black const;"
                            "};");
        newf->setBuddy(name);
        connect(name, &QLineEdit::textChanged, this, &newF::TextChanged);
    
        ok = new QPushButton("OK",this);
        ok->setStyleSheet("QPushButton {"
                          "background-color: #696969;"
                          "border: none;"
                          "}"
                          "QPushButton:hover {"
                          "background-color: #7D7D7D;"
                          "}");
        ok->setDefault(true);
        ok->setEnabled(false);
        ok->setFixedSize(100, 17);
        connect(ok,&QPushButton::clicked,this,&newF::Ok);
        QPushButton *cancel = new QPushButton("Cancel",this);
        cancel->setStyleSheet("QPushButton {"
                              "background-color: #696969;"
                              "border: none;"
                              "}"
                              "QPushButton:hover {"
                              "background-color: #7D7D7D;"
                              "}");
        cancel->setFixedSize(100, 17);
        connect(cancel,SIGNAL(clicked()),this,SLOT(close()));
    
        QHBoxLayout *hb1 = new QHBoxLayout;
        hb1->addWidget(newf);
        hb1->addWidget(name);
        QHBoxLayout *hb = new QHBoxLayout;
        hb->addWidget(ok);
        hb->addWidget(cancel);
        QVBoxLayout *vb = new QVBoxLayout;
        vb->addLayout(hb1);
        vb->addLayout(hb);
    
        setLayout(vb);
    }
    
    newF::~newF()
    {
        delete ui;
    }
    
    void newF::Ok(){
        projectWindow *pw = new projectWindow();
        pw->show();
        close();
    }
    
    void newF::paintEvent(QPaintEvent *event){
        Q_UNUSED(event);
        QPainter painter(this);
        painter.setPen(QPen(Qt::black, 40, Qt::SolidLine, Qt::FlatCap));
        painter.drawLine(0, 0, 230, 0);
    
    }
    
    void newF::mousePressEvent(QMouseEvent *event)
    {
        QPoint winPt  = this->pos();
        QPoint mousePt = event->globalPos();
    
        m_Position = mousePt - winPt;
    }
    
    
    void newF::mouseMoveEvent(QMouseEvent *event)
    {
        this->move(event->globalPos() - m_Position);
    }
    
    
    void newF::TextChanged(QString){
        QString names;
        names = name->text();
        if(names!="")
           ok->setEnabled(true);
        else
           ok->setEnabled(false);
    }
    
    
      //create new file
    void MainWindow::newfile(){
        newF *newf = new newF();
        newf->show();
    }
    
           //new
            newFile = new QAction (tr("New"),this);
              newFile->setShortcut(QKeySequence::New);
              connect(newFile,&QAction::triggered,this, &MainWindow::newfile);
              file->addAction(newFile);
    

  • Lifetime Qt Champion

    What part don't you understand ?
    I put in comments in sample.

    Ask about the places you are unsure about.


Log in to reply