Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/150.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 以巧妙的方式禁用QCheckbox_C++_Qt_Qt4_Checkbox - Fatal编程技术网

C++ 以巧妙的方式禁用QCheckbox

C++ 以巧妙的方式禁用QCheckbox,c++,qt,qt4,checkbox,C++,Qt,Qt4,Checkbox,我想让一个名为“显示标题”的QCheckBox在选中第一个复选框时禁用另一个名为“如果没有标题,则显示标题”的QCheckBox,但我的问题是,如何在用户选中第一个复选框时立即禁用它 SetupSlideShow::SetupSlideShow(QWidget* parent) : QScrollArea(parent), d(new SetupSlideShowPriv) { QWidget* panel = new QWidget(viewport()); setWi

我想让一个名为“显示标题”的QCheckBox在选中第一个复选框时禁用另一个名为“如果没有标题,则显示标题”的QCheckBox,但我的问题是,如何在用户选中第一个复选框时立即禁用它

SetupSlideShow::SetupSlideShow(QWidget* parent)
    : QScrollArea(parent), d(new SetupSlideShowPriv)
{
    QWidget* panel = new QWidget(viewport());
    setWidget(panel);
    setWidgetResizable(true);

    QVBoxLayout* layout = new QVBoxLayout(panel);

    d->showComment = new QCheckBox(i18n("Show captions"), panel);
    d->showComment->setWhatsThis( i18n("Show the image caption at the bottom of the screen."));

    d->showTitle = new QGroupBox(i18n("Show title"), panel);
    d->showTitle->setWhatsThis( i18n("Show the image title at the bottom of the screen."));
    d->showTitle->setCheckable(true);

    d->showCapIfNoTitle = new QCheckBox(i18n("Show captions if no title"), panel);
    d->showCapIfNoTitle->setWhatsThis( i18n("Show the image caption at the bottom of the screen if no titles existed."));
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addWidget(d->showCapIfNoTitle);
    d->showTitle->setLayout(vbox);
    layout->addWidget(d->showLabels);
    layout->addWidget(d->showComment);
    layout->addWidget(d->showTitle);
}

调用
paintEvent()
实际上对您的即时性没有任何帮助。在控件返回到事件循环之前(在构造函数退出之后),不会重新绘制任何内容。调用
update()
更为典型,但即使在更改内置小部件的属性时,也不需要这样做


要链接复选框,请为
showcoment
stateChanged()
信号定义一个插槽,将该信号连接到上面构造函数中的插槽(通过调用
connect()
,并在该插槽中调用
d->showCapIfNoTitle->setCheckState(d->showcoment->checkState())
调用
paintEvent()
在即时性方面并没有真正为您做任何事情。在控件返回到事件循环之前(在构造函数退出之后),不会重新绘制任何内容。调用
update()
更为典型,但即使在更改内置小部件的属性时,也不需要这样做

要链接复选框,请为
showcoment
stateChanged()
信号定义一个插槽,将该信号连接到上面构造函数中的插槽(通过调用
connect()
,然后在该插槽中,调用
d->showCapIfNoTitle->setCheckState(d->showcoment->checkState())
这不起作用吗

连接(d->showcoment,信号(切换(bool)),d->showCapIfNoTitle,插槽(设置禁用(bool))

这不管用吗

连接(d->showcoment,信号(切换(bool)),d->showCapIfNoTitle,插槽(设置禁用(bool))


如果按钮应该是互斥的,则使用单选按钮。和/或使用QButtonGroup。如果按钮应该是互斥的,则使用单选按钮。和/或使用QButtonGroup。如果在插槽中选中“显示标题”复选框时,我还想取消选中“如果没有标题则显示标题”复选框,该怎么办(setChecked(bool))?好的,没有默认的插槽。(我查看了文档。4.8文档没有指向继承成员的链接,如4.7,这很烦人,可能会绊倒一些新手。)您需要在SetupSlideShow中定义一个新的插槽,使用bool参数调用d->showCapIfNoTitle->setChecked()使用相反的值,或子类QCheckBox并添加一个setUnchecked(bool)slot.:)如果我还想在用slot(setChecked(bool))选中“Show captions if no titles”复选框时取消选中“Show captions if no titles”复选框,该怎么办?AFAIK,因为没有默认的slot。(我查看了文档。4.8文档没有像4.7中那样指向继承成员的链接,这很烦人,可能会让一些新手绊倒。)您需要在SetupSlideShow中定义一个新的插槽,并使用bool参数调用d->showCapIfNoTitle->setChecked()使用相反的值,或子类QCheckBox并添加一个setUnchecked(bool)插槽。:)