Qt源码分析--QWidget(1)--Window functions

本文详细介绍了Qt库中关于窗口管理的几个关键函数:show()用于显示窗口及其子窗口,依据平台默认行为选择全屏或最大化;hide()用于隐藏窗口;raise()使窗口置于顶层;lower()则将其置于底层。这些函数在窗口显示和层级控制中起着重要作用。

1.void show();

/*!
    Shows the widget and its child widgets.
    This is equivalent to calling showFullScreen(), showMaximized(), or setVisible(true),
    depending on the platform's default behavior for the window flags.
     \sa raise(), showEvent(), hide(), setVisible(), showMinimized(), showMaximized(),
    showNormal(), isVisible(), windowFlags()
*/
void QWidget::show()
{
    Qt::WindowState defaultState = QGuiApplicationPrivate::platformIntegration()->defaultWindowState(data->window_flags);
    if (defaultState == Qt::WindowFullScreen)
        showFullScreen();
    else if (defaultState == Qt::WindowMaximized)
        showMaximized();
    else
        setVisible(true); // Don't call showNormal() as not to clobber Qt::Window(Max/Min)imized
}

/*!
    Shows the widget in full-screen mode.
    Calling this function only affects \l{isWindow()}{windows}.
    To return from full-screen mode, call showNormal().
    Full-screen mode works fine under Windows, but has certain
    problems under X. These problems are due to limitations of the
    ICCCM protocol that specifies the communication between X11
    clients and the window manager. ICCCM simply does not understand
    the concept of non-decorated full-screen windows. Therefore, the
    best we can do is to request a borderless window and place and
    resize it to fill the entire screen. Depending on the window
    manager, this may or may not work. The borderless window is
    requested using MOTIF hints, which are at least partially
    supported by virtually all modern window managers.
    An alternative would be to bypass the window manager entirely and
    create a window with the Qt::X11BypassWindowManagerHint flag. This
    has other severe problems though, like totally broken keyboard focus
    and very strange effects on desktop changes or when the user raises
    other windows.
    X11 window managers that follow modern post-ICCCM specifications
    support full-screen mode properly.
    \sa showNormal(), showMaximized(), show(), hide(), isVisible()
*/
void QWidget::showFullScreen()
{
    ensurePolished();
    setWindowState((windowState() & ~(Qt::WindowMinimized | Qt::WindowMaximized))
                   | Qt::WindowFullScreen);
    setVisible(true);
#if !defined Q_OS_QNX // On QNX this window will 
### 如何在 QT 中集成和使用 OpenCV #### 1. 安装与准备 为了在 QT 中成功使用 OpenCV,首先需要确保两者的环境已正确安装并完成必要的配置。这包括下载适合的 OpenCV 版本以及将其编译为兼容的形式[^4]。 对于 Windows 用户而言,推荐直接从官方发布页面获取预编译好的二进制文件,并解压至目标位置以便后续操作;而对于 Linux 或 macOS 平台,则可以选择源码自行构建或者利用包管理器简化流程[^1]。 #### 2. 配置 PRO 文件 一旦确认基础依赖项均已就绪,下一步便是修改项目的 `.pro` 文件来加载所需的头文件路径及链接相应的静态/动态库: ```plaintext INCLUDEPATH += E:/OpenCV/opencv/build/include \ E:/OpenCV/opencv/build/include/opencv \ E:/OpenCV/opencv/build/include/opencv2 LIBS += -LE:/OpenCV/opencv/build/x64/vc15/lib \ -lopencv_core450.dll \ -lopencv_highgui450.dll \ -lopencv_imgproc450.dll \ -lopencv_imgcodecs450.dll ``` 上述示例适用于特定版本 (如 `4.x`) 和架构下的 MinGW 编译器设置情况,在实际应用过程中需依据实际情况调整具体参数值[^3]。 另外一种常见做法是在 Unix 类系统上采用相对固定的命名模式导入核心组件及其扩展模块支持: ```plaintext INCLUDEPATH += /usr/local/include/opencv4/ LIBS += -L/usr/local/lib/ \ -lopencv_core \ -lopencv_highgui \ -lopencv_imgproc \ -lopencv_imgcodecs ``` 此方法假设所有必需资源均已被妥善安置于标准目录结构之下[^5]。 #### 3. 示例代码展示 下面给出一段简单的 C++ 程序片段用于演示如何借助 OpenCV 实现基本功能——读取一幅图像并将结果显示在一个 QLabel 控件之上: ```cpp #include <QApplication> #include <QWidget> #include <QLabel> #include <cv.h> // opencv core library header file. #include <highgui.h> // GUI related functions. int main(int argc, char *argv[]) { QApplication app(argc, argv); cv::Mat image; image = cv::imread("example.jpg", CV_LOAD_IMAGE_COLOR); // Load an image from disk. if (!image.data) { // Check for invalid input. qDebug() << "Could not open or find the image!"; return -1; } QImage qImage((uchar*)image.data, image.cols, image.rows, static_cast<int>(image.step), QImage::Format_RGB888).rgbSwapped(); // Convert Mat to QImage format. QWidget window; // Create a widget as our main container. QLabel label(&window); label.setPixmap(QPixmap::fromImage(qImage)); // Set pixmap on label with converted image data. label.resize(qImage.size()); window.setWindowTitle("Display Image"); window.show(); return app.exec(); } ``` 以上程序展示了如何将 OpenCV 处理后的数据转换成 Qt 支持的数据类型并通过界面控件呈现出来。 ---
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

天天进步2015

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值