QT乱翻书-QWidget

QWidget

  窗口类。

#include <QApplication>
#include <QLabel>
#include <QWidget>

int main1(int argc, char* argv[])
{
    QApplication a(argc, argv);
    QWidget* widget = new QWidget();
    widget->setWindowTitle(QObject::tr("我是widget"));
    QLabel* label = new QLabel();
    label->setWindowTitle(QObject::tr("我是label"));
    label->setText(QObject::tr("label:我是个窗口"));
    label->resize(180, 20);
    QLabel* label2 = new QLabel(widget);
    label2->setText(QObject::tr("label2:我是widget的子部件"));
    label2->resize(250, 20);
    label->show();
    widget->show();
    int ret = a.exec();
    delete label;
    delete widget;
    return ret ;
}
#include <QApplication>
#include <QLabel>
#include <QWidget>

int main2(int argc, char* argv[])
{
    QApplication a(argc, argv);
    //产生一个无边框的窗口
//    QWidget* widget = new QWidget(0, Qt::Dialog | Qt::FramelessWindowHint);
    QWidget* widget = new QWidget(0, Qt::Dialog);

    widget->setWindowTitle(QObject::tr("我是widget"));
    //表示该窗口为启动画面
    QLabel* label = new QLabel(0, Qt::SplashScreen | Qt::WindowStaysOnTopHint);
    label->setWindowTitle(QObject::tr("我是label"));
    label->setText(QObject::tr("label:我是个窗口"));
    label->resize(180, 20);

    QLabel* label2 = new QLabel(widget);
    label2->setText(QObject::tr("label2:我是widget的子部件"));
    label2->resize(250, 20);

    label->show();
    widget->show();

    int ret = a.exec();
    delete label;
    delete widget;
    return ret ;
}
#include <QApplication>
#include <QLabel>
#include <QWidget>
#include <QDebug>

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

    w.resize(400, 300);
    w.move(200, 100);
    w.show();
    int x = w.x();
    int y = w.y();

    qDebug() << x << "," << y;
    const QRect geometry = w.geometry();
    QRect frame = w.frameGeometry();

    qDebug() << "geometry:" << geometry << ",frame:" << frame;

    // geometry: QRect(201,138 400x300) ,frame: QRect(200,100 402x339)


    int ret = a.exec();

    return ret;
}

 

QT乱翻书-QWidget

上一篇:从零开始学“C“语(你有多久没看基础知识了?)


下一篇:一文带你通过Sentinel源码,读懂微服务限流底层原理!