C++ QInputDialog:确定和取消按钮:删除确定和取消的按钮图像
在对话框中,如何去掉“确定”和“取消”按钮中的图标C++ QInputDialog:确定和取消按钮:删除确定和取消的按钮图像,c++,qt,qt5,qinputdialog,C++,Qt,Qt5,Qinputdialog,在对话框中,如何去掉“确定”和“取消”按钮中的图标 请注意“取消”和“确定”的图标。我查看了属性按钮,无法找到如何删除它们。解决方案的策略是首先获取按钮,但这些按钮属于QDialogButtonBox,因此必须使用findChild()方法,然后重置图标,只有一个问题,即按钮是在必要时创建的,例如,当它可见时,或者当您更改okbuttonext或cancelbuttonext时。例如,在中,我们可以通过使其可见来强制它 #include <QApplication> #includ
请注意“取消”和“确定”的图标。我查看了属性按钮,无法找到如何删除它们。解决方案的策略是首先获取按钮,但这些按钮属于
QDialogButtonBox
,因此必须使用findChild()
方法,然后重置图标,只有一个问题,即按钮是在必要时创建的,例如,当它可见时,或者当您更改okbuttonext
或cancelbuttonext
时。例如,在中,我们可以通过使其可见来强制它
#include <QApplication>
#include <QInputDialog>
#include <QDebug>
#include <QAbstractButton>
#include <QDialogButtonBox>
static int getInt(QWidget *parent,
const QString &title,
const QString &label,
int value=0,
int min=-2147483647,
int max=2147483647,
int step=1,
bool *ok=nullptr,
Qt::WindowFlags flags=Qt::Widget)
{
QInputDialog dialog(parent, flags);
dialog.setWindowTitle(title);
dialog.setLabelText(label);
dialog.setIntRange(min, max);
dialog.setIntValue(value);
dialog.setIntStep(step);
dialog.setVisible(true);
for(QAbstractButton *btn: dialog.findChild<QDialogButtonBox*>()->buttons()){
btn->setIcon(QIcon());
}
int ret = dialog.exec();
if (ok)
*ok = !!ret;
if (ret) {
return dialog.intValue();
} else {
return value;
}
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
bool ok;
int res = getInt(nullptr, "Factorial Calc", "Factorial of:", 5, 0, 100, 1, &ok);
if(ok)
qDebug()<< res;
return 0;
}
- 父对象未传递给静态方法:
#包括
#包括
#包括
#包括
#包括
#包括
int main(int argc,char*argv[])
{
质量保证申请a(argc、argv);
QWidget小部件;
布尔ok;
QTimer::单次激发(0,[](){
对于(QWidget*小部件:QApplication::topLevelWidgets()){
if(QInputDialog*dialog=qobject_cast(小部件)){
对于(QAbstractButton*btn:dialog->findChild()->buttons()){
btn->setIcon(QIcon());
}
}
}
});
int res=QInputDialog::getInt(nullptr,“阶乘计算”,“阶乘的:”,5,0,100,1,&ok);
如果(确定)
qDebug()
#include <QApplication>
#include <QInputDialog>
#include <QDebug>
#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget widget;
bool ok;
QTimer::singleShot(0, [&widget](){
QInputDialog *dialog = widget.findChild<QInputDialog *>();
for(QAbstractButton *btn: dialog->findChild<QDialogButtonBox*>()->buttons()){
btn->setIcon(QIcon());
}
});
int res = QInputDialog::getInt(&widget, "Factorial Calc", "Factorial of:", 5, 0, 100, 1, &ok);
if(ok)
qDebug()<< res;
return 0;
}
#include <QApplication>
#include <QInputDialog>
#include <QDebug>
#include <QAbstractButton>
#include <QDialogButtonBox>
#include <QTimer>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget widget;
bool ok;
QTimer::singleShot(0, [](){
for(QWidget *widget: QApplication::topLevelWidgets()){
if(QInputDialog *dialog = qobject_cast<QInputDialog*>(widget)){
for(QAbstractButton *btn: dialog->findChild<QDialogButtonBox*>()->buttons()){
btn->setIcon(QIcon());
}
}
}
});
int res = QInputDialog::getInt(nullptr, "Factorial Calc", "Factorial of:", 5, 0, 100, 1, &ok);
if(ok)
qDebug()<< res;
return 0;
}