QTSize

本文详细介绍了Qt界面设计中部件的大小策略,包括sizeHint和minimumSizeHint属性的使用,以及FormLayout的各种属性,如部件大小变化方式、是否换行和标签对齐方式等。这些属性对于创建用户友好的界面布局至关重要。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sizePolicy

  • 大小提示(sizeHint)、最小大小提示(minimumSizeHint)
  • sizeHint:属性保存了部件的建议大小,对于不同的部件,默认了不同的大小提示。可用sizeHint()函数获取其值
  • minimumSizeHint:保存了一个建议的最小大小。可用minnimunSizeHint()函数来获取其值
  • 如果使用了minimumSizeHint设置部件大小,则sizeHint将会被会被忽略

好像就使用过 Fixed...

 

FormLayout属性

 属性
  
  说明
  
  值
  
  说明
  
  

layoutFieldGrowthPolicy

  
  指定部件的大小变化方式
  
  AllNonFixeldsGrow
  
  所有的部件都被拉伸,这是默认值
  
  FieldsStayAtSizeHint
  
  所有的部件都使用sizeHint提供的大小
  
  ExpandingFieldsGrow
  
  大小策略为Expanding的部件会被拉伸
  
  layoutRowWrapPolicy
  
  设置是否换行
  如果需要换行
  则是将输入部件放到
  相应的标签下面
  
  DontWrapRows
  
  不换行,这是默认值
  
  WrapLongRows
  
  将较长的行进行换行
  
  WrapAllRows
  
  将所有行都换行,这样所有的输入部件都会放置在相应的标签下面
  
  layoutLabelAlignment
  
  设置标签的对齐方式
  分别为水平方向
  垂直方向
  
  水平方向
  
  AlignLeft
  
  左对齐
  
  AlingnRight
  
  右对齐
  
  AlingnHCenter
  
  水平居中对齐
  
  AlignJustify
  
  两端对齐
  
  垂直方向
  
  AlignTop
  
  顶对齐
  
  AlignBottom
  
  底对齐
  
  AlignVCenter
  
  垂直居中对齐
  
  layoutFormAlignment
  
  设置部件在表单中对齐方式
  
  

同layoutLabelAligent

LayoutSizeConstraint取值:

真的太多了,用到了再回来查呗~

 

参考:

不二如是:https://fishc.com.cn/forum.php?mod=viewthread&tid=76676&extra=page%3D5%26filter%3Dauthor%26orderby%3Ddateline%26typeid%3D449

; ===== 主程序:读取、显示单波段影像并计算统计信息 ===== pro binary, filename ; 检查文件是否存在 if ~file_test(filename) then begin print, '错误: 文件不存在 - ', filename return endif ; 根据文件扩展名选择读取方法 file_ext = strmid(filename, strpos(filename, '.', /reverse_search) + 1) file_ext = strlowcase(file_ext) ; 处理JPG/JPEG图像 if (file_ext eq 'jpg') or (file_ext eq 'jpeg') then begin ; 读取JPG图像 read_jpeg, filename, image, /quiet ; 如果是RGB图像,转换为灰度 if (size(image, /n_dimensions) eq 3) then begin print, '检测到RGB图像,转换为灰度...' image = reform(0.299*image[0,*,*] + 0.587*image[1,*,*] + 0.114*image[2,*,*]) endif endif ; 处理TIFF图像 if (file_ext eq 'tif') or (file_ext eq 'tiff') then begin ; 读取TIFF图像 image = read_tiff(filename) ; 如果是多波段图像,取第一个波段 if (size(image, /n_dimensions) gt 2) then begin print, '检测到多波段图像,使用第一个波段...' image = image[*,*,0] endif endif ; 处理不支持的格式 if (file_ext ne 'jpg') and (file_ext ne 'jpeg') and (file_ext ne 'tif') and (file_ext ne 'tiff') then begin print, '错误: 不支持的文件格式 - ', file_ext return endif ; 获取图像尺寸 dims = size(image) cols = dims[1] rows = dims[2] ; 创建窗口显示图像(按实际尺寸) window, /free, xsize=cols, ysize=rows, title='图像显示: ' + filename ; 显示图像(根据数据类型调整显示范围) data_type = size(image, /type) data_type = fix(data_type) ; 使用单独的IF语句而不是ELSE IF if data_type eq 1 then begin tv, bytscl(image) ; byte类型 endif if data_type eq 2 then begin tv, bytscl(image, min=min(image), max=max(image)) ; int类型 endif if data_type eq 3 then begin tv, bytscl(image, min=min(image), max=max(image)) ; long类型 endif if data_type eq 4 then begin tv, bytscl(image) ; float类型 endif if data_type eq 5 then begin tv, bytscl(image) ; double类型 endif if data_type eq 12 then begin tv, bytscl(image) ; uint类型 endif if (data_type ne 1) and (data_type ne 2) and (data_type ne 3) and (data_type ne 4) and (data_type ne 5) and (data_type ne 12) then begin tv, image endif ; 计算统计信息 image_mean = mean(image) image_min = min(image) image_max = max(image) image_stddev = stddev(image) image_variance = variance(image) ; 在图像上显示统计信息 text = '均值: ' + string(image_mean, format='(F8.2)') + $ ' 最小值: ' + string(image_min) + $ ' 最大值: ' + string(image_max) + $ ' 标准差: ' + string(image_stddev, format='(F8.2)') + $ ' 方差: ' + string(image_variance, format='(F8.2)') ; 创建文本背景 text_dims = textsize(text) text_width = text_dims[0] text_height = text_dims[1] xpos = (cols - text_width)/2 ypos = rows - text_height - 10 ; 绘制半透明背景 device, decomposed=0 polyfill, [xpos-5, xpos+text_width+5, xpos+text_width+5, xpos-5], $ [ypos-5, ypos-5, ypos+text_height+5, ypos+text_height+5], $ /device, color=0, fill_color=0, background=0.7, transparency=50 ; 显示统计信息文本 xyouts, xpos, ypos, text, /normal, color=255, font='helvetica', size=1.2 ; 显示文件名 xyouts, 10, 10, filename, /normal, color=255, font='helvetica', size=1.0 ; 打印统计信息到控制台 print, '===== 图像统计信息 =====' print, '文件: ', filename print, '尺寸: ', cols, 'x', rows, ' 像素' print, '数据类型: ', data_type print, '最小值: ', image_min print, '最大值: ', image_max print, '均值: ', image_mean print, '标准差: ', image_stddev print, '方差: ', image_variance print, '========================' ; 保存统计信息到文本文件 outfile = file_dirname(filename) + '/' + file_basename(filename, '.') + '_stats.txt' openw, lun, outfile, /get_lun printf, lun, '===== 图像统计信息 =====' printf, lun, '文件: ' + filename printf, lun, '尺寸: ' + string(cols) + 'x' + string(rows) + ' 像素' printf, lun, '数据类型: ' + string(data_type) printf, lun, '最小值: ' + string(image_min) printf, lun, '最大值: ' + string(image_max) printf, lun, '均值: ' + string(image_mean) printf, lun, '标准差: ' + string(image_stddev) printf, lun, '方差: ' + string(image_variance) printf, lun, '========================' free_lun, lun print, '统计信息已保存到: ', outfile ; 等待用户关闭窗口 print, '按任意键关闭窗口...' key = '' ; 初始化变量 wait, key ; 等待按键 wdelete, !d.window end出现IDL> .compile -v 'D:\Harris\IDLwork\Default\binary.pro' % Compiled module: BINARY. IDL> binary, 'D:\five\p5.jpg' % Variable is undefined: TEXTSIZE. % Execution halted at: BINARY 91 D:\Harris\IDLwork\Default\binary.pro % $MAIN$
最新发布
06-14
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sssnial-jz

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值