簡體   English   中英

在Qt中可調整大小和最大化窗口

[英]Resizable and maximizable window in Qt

我有一個使用Qt打開窗口的c ++程序,但該窗口無法調整大小,並且缺少最大化按鈕。
大多數代碼是從教程中復制的。
請參閱:http: //zetcode.com/tutorials/qt4tutorial/firstprograms/
這正常嗎? 這是我的代碼:

#include <QApplication>
#include <QDesktopWidget>
#include <QWidget>
#include <QIcon>
#include <QPushButton>
#include <QTextEdit>

using namespace std;

class Frame : public QWidget {
    public: Frame(QWidget *parent = 0);
};

void center(QWidget *widget, int w, int h) {
    int x, y;
    int screenWidth;
    int screenHeight;

    QDesktopWidget *desktop = QApplication::desktop();

    screenWidth = desktop->width();
    screenHeight = desktop->height();

    x = (screenWidth - w) / 2;
    y = (screenHeight - h) / 2;

    widget->move( x, y );
}

Frame::Frame(QWidget *parent) : QWidget(parent) {
    int WIDTH = 250;
    int HEIGHT = 150;

    setFixedSize(WIDTH, HEIGHT);

    QTextEdit *edit = new QTextEdit(this);
    edit -> setGeometry(5, 5, 200, 150);

    QPushButton *quit = new QPushButton("Quit", this);
    quit->setGeometry(50, 40, 75, 30);

    center(this, WIDTH, HEIGHT);

    connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
}

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    Frame window;

    window.setWindowTitle("My window");
    window.setWindowIcon(QIcon("image.jpg"));
    window.show();

    return app.exec();
}

在窗口小部件構造函數中使用setWindowFlags(Qt::WindowMinimizeButtonHint|Qt::WindowMaximizeButtonHint|Qt::Window)

這里查看更多

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM