最初设置后是否有任何方法可以重置样式表
我是QT的新手。我有8个QT QPUSHBUTTON,就像此图像一样。
要求
单击任何按钮后,其边框将用黑色圆圈突出显示。 仅当单击8个新按钮中,突出显示的边框才能消失,并且在运行时,黑色圆圈应包围该新按钮。
注意:圆圈应一次单击一个按钮周围环绕。
尝试:
的Red Circle,
button1->setStyleSheet("QPushButton {background-color: rgb(200,0,0),border-radiu:15px}") ;
我是使用此代码在QT表单类中单击插槽中
void button1clicked()
{
button1->setStyleSheet("QPushButton {border-style:solid; border-width:3px; border-color:black;}") ;
}
我如何第二次更改样式表?
我已经访问过这个
通过setStyleSheet()在QT中不丢失Orignal样式?
并应用了此解决方案,但它不起作用?
setStyleSheet("background-color: rgb(200,0,0),border-radiu:15px");
setStyleSheet( styleSheet().append(QString("border-style:solid; border-width:3px; border-color:black;")) );
我如何解决这个问题?
I am new in QT. I have 8 QT QPushButton like in this image.
Requirement
After clicking any button its border is highlighted with a black circle. The highlighted border should disappear only when any new button among the 8 is clicked and a black circle should encircle around that new button at run time.
Note: Circle should encircle around one button at a time which is clicked.
Attempt:
I am made the red circle using this code in QT form class
button1->setStyleSheet("QPushButton {background-color: rgb(200,0,0),border-radiu:15px}") ;
In button clicked slot I am
void button1clicked()
{
button1->setStyleSheet("QPushButton {border-style:solid; border-width:3px; border-color:black;}") ;
}
How do change the style sheet for a second time?
I have visited this
How to add style via setStyleSheet() without losing orignal style in Qt?
and applied this solution but it didn't work?
setStyleSheet("background-color: rgb(200,0,0),border-radiu:15px");
setStyleSheet( styleSheet().append(QString("border-style:solid; border-width:3px; border-color:black;")) );
How I can solve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在UI文件中添加此样式表:
mainWindow.h:
mainWindow.cpp :
结果:
Add this stylesheet in your UI File :
mainwindow.h:
mainwindow.cpp:
The Result:
似乎您将样式表设置在窗口上,而不是按钮本身。因此,尝试此操作:
更新:
这是一种有效的方法:
mainwindow.h:
mainwindow.cpp:
ui包含从按钮1到按钮8的8个按钮。
这是结果:

Seems you're setting styleSheet to your window, not button's itself. So try this one:
UPDATED:
Here's a way that works:
mainwindow.h:
mainwindow.cpp:
UI contains 8 buttons from button1 to button8.
Here's the result:

传递样式表文字时,您必须谨慎
基于此处的文档。您需要设置样式表,如下所示:
然后将是默认值。
You have to be carefully when passing the style sheet text,
based on the DOC here .. you need to set the stylesheet like below:
Then it will be restord to default.