Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QWidget Modal
Forum Updated to NodeBB v4.3 + New Features

QWidget Modal

Scheduled Pinned Locked Moved Mobile and Embedded
10 Posts 2 Posters 4.3k 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.
  • F Offline
    F Offline
    f3tz3r
    wrote on last edited by
    #1

    I'm running QT Embedded on OpenSuse linux through the frambuffer, so no x windows. This is also being ran on a 15in touch screen unit.

    My goal:
    To instantiate a class that requires interaction before further process. A Modal window would be ideal.

    My problem:
    Ideally i'd like to use QDialog, remove the title bar and all its buttons, and put a custom border on it; however, every flag combination i've tried doesn't give me the desired effect.

    When i do the following:
    @this->setWindowFlags( Qt::CustomizeWindowHint | Qt::Dialog);@

    I sort of get what i want. The title bar is removed, but there is no border replacing it. In essence, i now have a dialog with a left, bottom, and right blue border.

    I've also tried using CSS to style the CDialog to no avail. The following is the CSS that i attempted:
    @QDialog{
    border-width: 5px;
    border-color: black;
    }
    @

    I've now gone to attempting to do this with a QWidget. After about an hour of researching, it looks like i cant make the QWidget be modal.

    If anyone has an idea for this, it would be greatly appreciated.

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

      Hi and welcome to devnet,

      Are you showing your widget full screen ?

      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
      • F Offline
        F Offline
        f3tz3r
        wrote on last edited by
        #3

        No, the widget isn't full screen. With the current widget implementation, I don't even see the widget. I believe this is because the code doesn't pause execution while the widget is shown.

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

          Can you show the implementation ?

          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
          • F Offline
            F Offline
            f3tz3r
            wrote on last edited by
            #5

            I think this is all of it. If there is something blaringly wrong, let me know. I'm going back and forth trying to get this to work.

            This morning i had the idea to use the QDialog again. Instead of using the QDialog as a QGridLayout parent, i turned the hierarchy like this: QDialog -> QFrame -> QGridLayout.

            This implementation looked like the QFrame was inheriting the window flags from QDialog as i couldn't set a border on the QFrame.

            mainwindow.cpp:

            @void MainWindow::on_button_clicked(){

            MessageBox confirmationDialog(this);
            
            confirmationDialog.show();
            

            }
            @

            messagebox.h:

            @
            class MessageBox : public QWidget
            {
            Q_OBJECT
            public:
            QLabel _title;

            explicit MessageBox(QWidget *parent = 0);
            void setButtonMode(int mode);
            void setupLayout(int mode);
            

            signals:

            public slots:

            };

            @

            messagebox.cpp
            @

            MessageBox::MessageBox(QWidget *parent) : QWidget(parent), _layout(this){

            this->setWindowModality(Qt::WindowModal);
            
            this->setButtonMode(2);
            
            this->setupLayout(2);
            

            }

            void MessageBox::setButtonMode(int mode){

            switch(mode){
            case 1:
                //QObject::connect(&this->_okButton, SIGNAL(clicked()), this, SLOT(accept()));
                break;
            case 2:
                //QObject::connect(&this->_saveButton, SIGNAL(clicked()), this, SLOT(accept()));
                //QObject::connect(&this->_cancelButton, SIGNAL(clicked()), this, SLOT(accept()));
                break;
            default:
            }
            

            }

            void MessageBox::setupLayout(int mode){

            QFile styleFile("messagebox.css");
            styleFile.open(QFile::ReadOnly);
            QString style(styleFile.readAll());
            
            this->setStyleSheet(style);
            
            switch(mode){
            case 1:
                break;
            case 2:
            
                this->_title.setText("Confirm new prices");
                this->_title.setStyleSheet("font-weight:24pt;");
            
                this->_layout.addWidget(&this->_title, 1, 1);
            
            
                break;
            default:
                break;
            }
            

            }

            @

            messagebox.css:
            @QWidget{
            border-width: 5px;
            border-color: black;
            }
            @

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

              @
              void MainWindow::on_button_clicked(){
              MessageBox confirmationDialog(this);
              confirmationDialog.show();
              } << confirmationDialog is destroyed here
              @

              So either use exec or allocate it on the heap

              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
              • F Offline
                F Offline
                f3tz3r
                wrote on last edited by
                #7

                Sorry for the late response. I did get this to function as i desired. Here are the steps that i took:

                1. Created a higher level widget that was transparent and set the size to the entire screen.
                2. Created my messagebox as a child of the full screen widget.

                With this implementation, nothing in the background could be touched, but any buttons on the message box worked

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  f3tz3r
                  wrote on last edited by
                  #8

                  Sorry for the late response. I did get this to function as i desired. Here are the steps that i took:

                  1. Created a higher level widget that was transparent and set the size to the entire screen.
                  2. Created my messagebox as a child of the full screen widget.

                  With this implementation, nothing in the background could be touched, but any buttons on the message box worked

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

                    Wasn't the call to exec enough ?

                    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
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Wasn't the call to exec enough ?

                      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