Qt中的控件可以使用代码添加也可以通过界面编辑器手工拖拽,问题是那些拖拽的控件不能体现在代码里吗?我想针对控件做一些微调(譬如全屏窗口时,某个label依然居中)。这个好像只能通过代码修改布局吧。遇到这种问题时,怎么处理呢?还是你们都是用代码添加控件的?
伊谢尔伦2017-04-17 11:35:26
(I haven’t used Qt for a long time. I was using Qt4 at that time, but it hasn’t changed much)
The UI designer outputs a .ui file. The .ui file will be compiled by uic into ui_WidgetXXOO.h during compilation, which defines a Ui_WidgetXXOO class, which contains all the files added by drag and drop in the designer. The control corresponds to the variable, and then there is a setupUi function, which is used to complete the modifications you make to the control in the designer.
Go back to the WidgetXXOO class, which will contain this ui_WidgetXXOO.h, and then call Ui_WidgetXXOO::setupUi in the constructor with this as the parameter to load the controls you added through the designer and the modifications you made.
How the above UI designer works, you can use Qt Creator to create a default project, and you can see the codes I mentioned above. It is a transparent working process. If you need to write code and modify the control yourself, you only need to write the code you want to add in the constructor of WidgetXXOO, followed by Ui_WidgetXXOO::setupUi.
In Qt development, the UI designer is a very useful tool. Usually, you can use the UI designer by dragging it directly, and then write your own code on this basis to complete the work that cannot be done through the UI designer.
PHP中文网2017-04-17 11:35:26
The interface editor actually edits the .ui file. You can directly open the .ui file with a text editor for editing. These dragged controls can be obtained through the UI object, so even the dragged controls can be dynamically controlled by code.