c++ - 是否可以从 qt QColumnView 中删除预览小部件?

标签 c++ qt

我需要在 qt View 中显示一组分层数据。我正在使用 QColumnView 来显示模型。但是,有一个功能可以将 View 中的最后一列降级为预览小部件。有可能隐藏这个吗?例如,像 view.setPreviewWidget( NULL ) 这样的东西,尽管这会破坏程序

编辑:我应该澄清一下,我想要一种完全隐藏最后一列的方法,即让我 View 中的最后一列成为模型的“叶子”,并且没有预览空间

最佳答案

这将在单击时隐藏按钮。

#include <QtGui/QApplication>
#include <QtGui/QColumnView>
#include <QtGui/QPushButton>
#include <QtGui/QFileSystemModel>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QColumnView view;
    QFileSystemModel model;
    QPushButton button(&view);

    button.setText("Click me");
    QObject::connect(&button, SIGNAL(clicked()), &button, SLOT(hide()));

    model.setRootPath("/");

    view.setModel(&model);
    view.setPreviewWidget(&button);
    view.show();

    return a.exec();
}

请注意,它将永远隐藏。如果你想让它再次显示,你必须调用 show()

关于c++ - 是否可以从 qt QColumnView 中删除预览小部件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3419185/

相关文章:

c++ - 理解大代码

c++ - 为什么我总是在 C++ 中得到奇怪的输出

c++ - 匿名函数, "Parse Issue: Expected Expression"

c++ - MySQL C++ 连接器 : How do I get the thread/connection Id?

c++ - 如何分配和更改 QString 的值?

c++ - 将 QBuffer 用于二进制数据

c++ - Q_ASSERT 破坏了 C++ 异常处理

c++ - SDL_Addtimer 工作不一致或根本不工作

c++ - Qt 动态属性值改变时的调用方法

macos - Qt + cocoa : Undefined symbols for architecture x86_64