以一种棘手的方式禁用 QCheckbox

发布于 2024-12-22 03:39:32 字数 1236 浏览 1 评论 0原文

我想让一个名为“显示标题”的 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);
}

I want to make a QCheckBox named "Show Captions" disable another QCheckBox named "Show captions if no title" when the first is checked, but my problem is that how I can make it disabled immediately when the user checks the first checkbox.

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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

九局 2024-12-29 03:39:32

这行不通吗?

connect(d->showComment, SIGNAL(toggled(bool)), d->showCapIfNoTitle, SLOT(setDisabled(bool)));

Doesn't this work?

connect(d->showComment, SIGNAL(toggled(bool)), d->showCapIfNoTitle, SLOT(setDisabled(bool)));

找个人就嫁了吧 2024-12-29 03:39:32

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

要链接复选框,请为 showCommentstateChanged() 信号定义一个槽,将该信号连接到上面构造函数中的槽(通过调用 connect( ),并在该槽中调用 d->showCapIfNoTitle->setCheckState(d->showComment->checkState())

The call to paintEvent() isn't really doing anything for you regarding immediacy. Nothing will be repainted until control returns to the event loop (after your constructor exits). It is more typical to call update() but even this is unnecessary when changing the properties of built in widgets.

To link the check boxes, define a slot for the stateChanged() signal of showComment, connect the signal to your slot in your constructor above (by calling connect(), and in that slot, call d->showCapIfNoTitle->setCheckState(d->showComment->checkState()).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文