How to set StyleSheet for an specific label in QMessageBox?
-
wrote on 30 Jun 2020, 06:37 last edited by Muhammad Mirab Br. 7 Jan 2020, 05:54
I Want to have a bigger QMessageBox and centered texts in it but when I increase the size of it by stylsheet it'll be like this:
if I could give it Some Padding or margin it would be fixed but I can't.
void MainWindow::showMsg() { QMessageBox m_MsgBox; m_MsgBox.setWindowFlags(Qt::Window | Qt::FramelessWindowHint); m_MsgBox.setIcon(QMessageBox::Warning); m_MsgBox.setText("Your Trial is finished! Please purachase a plan."); m_MsgBox.setStandardButtons(QMessageBox::Ok); m_MsgBox.setStyleSheet("QLabel{min-width:200 px; font-size: 13px;} QPushButton{ width:25px; font-size: 13px; }"); if(m_MsgBox.exec() == QMessageBox::Ok) m_MsgBox.close(); }
I want to give different css properties to each QLabel(QMessageBox::Warning & setText) in this QMessageBox.
Any help will be appreciated. Thanks!
-
I Want to have a bigger QMessageBox and centered texts in it but when I increase the size of it by stylsheet it'll be like this:
if I could give it Some Padding or margin it would be fixed but I can't.
void MainWindow::showMsg() { QMessageBox m_MsgBox; m_MsgBox.setWindowFlags(Qt::Window | Qt::FramelessWindowHint); m_MsgBox.setIcon(QMessageBox::Warning); m_MsgBox.setText("Your Trial is finished! Please purachase a plan."); m_MsgBox.setStandardButtons(QMessageBox::Ok); m_MsgBox.setStyleSheet("QLabel{min-width:200 px; font-size: 13px;} QPushButton{ width:25px; font-size: 13px; }"); if(m_MsgBox.exec() == QMessageBox::Ok) m_MsgBox.close(); }
I want to give different css properties to each QLabel(QMessageBox::Warning & setText) in this QMessageBox.
Any help will be appreciated. Thanks!
wrote on 30 Jun 2020, 09:02 last edited by JonB@Muhammad-Mirab-Br said in How to set StyleSheet for an specific label in QMessageBox?:
min-width:200 px;
Probably not an issue, but if you are having a problem why do you put a space into
200px
in case that is not acceptable to QSS? Why make it different from all your otherXXpx
directives? -
wrote on 1 Jul 2020, 05:59 last edited by
-
wrote on 1 Jul 2020, 06:29 last edited by
Only answering to your topic title, if you look into the source code of QMessageBox, every label has a object name, so that should be easy to set different style to them by using ID selector.
-
text: "qt_msgbox_label"
-
icon: "qt_msgboxex_icon_label"
-
informativeText: "qt_msgbox_informativelabel"
Note: These names may change in future versions.
-
-
Only answering to your topic title, if you look into the source code of QMessageBox, every label has a object name, so that should be easy to set different style to them by using ID selector.
-
text: "qt_msgbox_label"
-
icon: "qt_msgboxex_icon_label"
-
informativeText: "qt_msgbox_informativelabel"
Note: These names may change in future versions.
wrote on 1 Jul 2020, 06:45 last edited by@Bonnie Thanks! This really helped. This is what I was searching for.
-
-
wrote on 1 Jul 2020, 08:17 last edited by
@Bonnie How can I Make the button center align in QMessagebox? I tried: move(), setGeometry() and etc.
At all, I want to make the button center. Thanks.
-
@Bonnie How can I Make the button center align in QMessagebox? I tried: move(), setGeometry() and etc.
At all, I want to make the button center. Thanks.
wrote on 1 Jul 2020, 08:40 last edited by Bonnie 7 Jan 2020, 08:41@Muhammad-Mirab-Br
Option 1: find QDialogButtonBox and set propertym_MsgBox.findChild<QDialogButtonBox*>(QString(), Qt::FindDirectChildrenOnly)->setCenterButtons(true);
Option 2: set property by stylesheet:
QDialogButtonBox { qproperty-centerButtons: true; }
-
@Muhammad-Mirab-Br
Option 1: find QDialogButtonBox and set propertym_MsgBox.findChild<QDialogButtonBox*>(QString(), Qt::FindDirectChildrenOnly)->setCenterButtons(true);
Option 2: set property by stylesheet:
QDialogButtonBox { qproperty-centerButtons: true; }
wrote on 1 Jul 2020, 09:17 last edited byThanks @Bonnie, You are AWESOME!
8/8