如何使 QPushButton 与其背景图像具有相同的尺寸?
我的主窗口上有一个 QPushButton:
practiceButton_ = new QPushButton(this);
practiceButton_->setText(_("Practice"));
practiceButton_->setObjectName("practiceButton");
然后我将一些样式与其关联:
qApp->setStyleSheet("QPushButton#practiceButton { background-image: url('myfile.png'); padding:0; margin:0; border:none; }");
背景图像显示出来,看起来样式已成功应用,但是该按钮比背景图像小。如何调整它的大小以适合其背景图像?
如果无法自动完成,是否可以在某处访问应用于按钮的样式,并根据它调整按钮的大小?如果可以的话,我只想避免对值进行硬编码。
I have a QPushButton on my main window:
practiceButton_ = new QPushButton(this);
practiceButton_->setText(_("Practice"));
practiceButton_->setObjectName("practiceButton");
Then I associate some style with it:
qApp->setStyleSheet("QPushButton#practiceButton { background-image: url('myfile.png'); padding:0; margin:0; border:none; }");
The background image shows up and it looks like the style is applied successfully, however the button is smaller than the background image. How can I make it resize to fit its background image?
If it cannot be done automatically, is it possible to access the style applied to the button somewhere, and resize the button based on it? I'd just like to avoid hard-coding the values if I can avoid it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我刚刚发现宽度和高度可以在 CSS 本身中设置,这可能是正确的方法:
Ok I just figured out that the width and height can be set in the CSS itself, which is probably the right way to do it: