简体   繁体   中英

Resizable and maximizable window in Qt

I have a c++ program that is using Qt to open a window, but the window isn't resizable and the maximize button is missing.
Most of the code is copied from a tutorial.
see: http://zetcode.com/tutorials/qt4tutorial/firstprograms/
Is this normal? Here is my code:

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

Use setWindowFlags(Qt::WindowMinimizeButtonHint|Qt::WindowMaximizeButtonHint|Qt::Window) in your widget constructor.

For more look here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM