Qt+VS resize fails to set the window size, setWindowTitle sets the window title fails, and Qt displays Chinese garbled characters.

First of all, let me talk about my environment. It is a Qt5.15 program written in VS.
The Qwididget created
is because resize and setWindowTitle cannot be used. There is a line at the bottom of the code

ui.setupUi(this);

It should set some default specifications of the UI interface
If you perform resize and setWindowTitle operations before this line of code, it will still change back after executing this line of code, so you will think It cannot be set, just comment it out.
In addition, there is a problem with Chinese garbled characters, please look at my code

#include "myWidget.h"
#include<qpushbutton.h>

myWidget::myWidget(QWidget *parent)
    : QMainWindow(parent)
{
    
    
    
    //创建一个按钮
    QPushButton* btn = new QPushButton;

    //让btn依赖在mywidget窗口中
    btn->setParent(this);

    //显示文本
    btn->setText(u8"第一个按钮");

    //创建第二个按钮   按照控件大小创建窗口
    QPushButton* btn2 = new QPushButton(u8"第二个按钮",this);


    btn->resize(btn2->size());
    btn->move(100, 0);


    resize(600, 600);
    //窗口标题
    setWindowTitle("第一个窗口");

    //ui.setupUi(this);
}

myWidget::~myWidget()
{
    
    }

Just add u8 in front of Chinese, which represents UTF-8 encoding.
Novices please do not comment. If you find anything wrong, please leave a message for guidance.

Guess you like

Origin blog.csdn.net/weixin_51315141/article/details/133807481