久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱

Qt: resizing a QLabel containing a QPixmap while keeping its aspect ratio(Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱橫比)
本文介紹了Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱橫比的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我使用 QLabel 向用戶顯示更大的、動態變化的 QPixmap 的內容.根據可用空間使這個標簽更小/更大會很好.屏幕尺寸并不總是像 QPixmap 一樣大.

I use a QLabel to display the content of a bigger, dynamically changing QPixmap to the user. It would be nice to make this label smaller/larger depending on the space available. The screen size is not always as big as the QPixmap.

如何修改 QLabel 的 QSizePolicysizeHint() 來調整 QPixmap 的大小,同時保持原始 QPixmap 的縱橫比?

How can I modify the QSizePolicy and sizeHint() of the QLabel to resize the QPixmap while keeping the aspect ratio of the original QPixmap?

我無法修改 QLabel 的 sizeHint(),將 minimumSize() 設置為零也無濟于事.在 QLabel 上設置 hasScaledContents() 允許增長,但會破壞縱橫比...

I can't modify sizeHint() of the QLabel, setting the minimumSize() to zero does not help. Setting hasScaledContents() on the QLabel allows growing, but breaks the aspect ratio thingy...

子類化 QLabel 確實有幫助,但是這個解決方案為一個簡單的問題添加了太多代碼......

Subclassing QLabel did help, but this solution adds too much code for just a simple problem...

是否有任何聰明的提示如何在沒有子類化的情況下實現這個?

Any smart hints how to accomplish this without subclassing?

推薦答案

為了更改標簽大小,您可以為標簽選擇合適的大小策略,例如擴展或最小擴展.

In order to change the label size you can select an appropriate size policy for the label like expanding or minimum expanding.

您可以通過在每次更改時保持縱橫比來縮放像素圖:

You can scale the pixmap by keeping its aspect ratio every time it changes:

QPixmap p; // load pixmap
// get label dimensions
int w = label->width();
int h = label->height();

// set a scaled pixmap to a w x h window keeping its aspect ratio 
label->setPixmap(p.scaled(w,h,Qt::KeepAspectRatio));

您應該在兩個地方添加此代碼:

There are two places where you should add this code:

  • 更新像素圖時
  • 在包含標簽的小部件的resizeEvent

這篇關于Qt:調整包含 QPixmap 的 QLabel 的大小,同時保持其縱橫比的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 成人精品一区二区 | 福利视频一区 | 福利视频日韩 | 精品国产一区二区三区性色 | 成人精品区 | 毛片一级片 | 国内91在线| 国产成人精品一区二区三区网站观看 | 国产成人免费网站 | 欧美日韩国产不卡 | 国产精品久久久久久久免费大片 | 91视在线国内在线播放酒店 | 免费午夜视频在线观看 | 色秀网站 | 在线成人免费视频 | 久免费视频 | 日本小视频网站 | 日韩中文字幕视频 | 久久久www成人免费精品张筱雨 | 久久久久国产一区二区三区 | 91在线精品一区二区 | 国产成人av电影 | 精品欧美一区二区三区 | 精品国产一区二区三区性色av | 热99视频| 欧美一区二区三区免费电影 | 亚洲性人人天天夜夜摸 | 二区av| 亚洲一区二区三区在线免费观看 | 91传媒在线观看 | 国产四区 | 国产日韩欧美在线观看 | 国产精品久久久久久久久 | 免费激情av | 亚洲av毛片| 日韩精品一二三 | 少妇久久久 | 久久精品日产第一区二区三区 | 99在线精品视频 | 欧美日韩精品亚洲 | 国产精品国产精品 |