QWidget Modal
-
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.
-
Hi and welcome to devnet,
Are you showing your widget full screen ?
-
Can you show the implementation ?
-
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;
}
@ -
@
void MainWindow::on_button_clicked(){
MessageBox confirmationDialog(this);
confirmationDialog.show();
} << confirmationDialog is destroyed here
@So either use exec or allocate it on the heap
-
Sorry for the late response. I did get this to function as i desired. Here are the steps that i took:
- Created a higher level widget that was transparent and set the size to the entire screen.
- 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
-
Sorry for the late response. I did get this to function as i desired. Here are the steps that i took:
- Created a higher level widget that was transparent and set the size to the entire screen.
- 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
-
Wasn't the call to exec enough ?
-
Wasn't the call to exec enough ?