开发者

Resizing a label inside a gridlayout?

开发者 https://www.devze.com 2023-04-06 03:05 出处:网络
I\'m learning Qt, maybe this is easy but I can\'t seem to figure it out. First, I have a file path in a QString, myPath. I开发者_Python百科 want to load it and show it in a window.

I'm learning Qt, maybe this is easy but I can't seem to figure it out.

First, I have a file path in a QString, myPath. I开发者_Python百科 want to load it and show it in a window.

Suppose I have a window with a label inside it:

QPixmap image(myPath);
ui->myLabel->setPixmap(image);
ui->myLabel->resize(image.size());

It works, but the on the right there is no border. I thought about fixing that with a gridlayout. I'm not sure if that's the appropriate solution however.

Anyway, that means I'd have a gridlayout in the window and then the label inside. But once I use that pice of code, the image is only as big as the gridlayout.

So, how can I have my image with some borders around it, and how can I have the gridlayout resize itself appropriately?


I'm not sure if I understood correctly but I believe you want some padding inside the label. That can be accomplished for example with QSS, Qt's flavor of CSS.

ui->myLabel->setStyleSheet("QLabel { padding: 10px; }"); 

should do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号