Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用样式表在Qt中圆角按钮?_Qt_Rounded Corners - Fatal编程技术网

如何使用样式表在Qt中圆角按钮?

如何使用样式表在Qt中圆角按钮?,qt,rounded-corners,Qt,Rounded Corners,我的应用程序中有按钮(Qt、视觉),我试图改变它们的样式:颜色、形状等。 我用过这样的东西: button->setStyleSheet(QString::fromUtf8("QPushButton{background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1," "stop: 0 white, stop: 1 grey);" "border-style: solid;" "border-width: 2px;"

我的应用程序中有按钮(Qt、视觉),我试图改变它们的样式:颜色、形状等。 我用过这样的东西:

button->setStyleSheet(QString::fromUtf8("QPushButton{background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,"
  "stop: 0 white, stop: 1 grey);"
  "border-style: solid;"
  "border-width: 2px;"
  "border-color: black;"
  "border-radius: 15px;}"));
但我得到的按钮有圆角的边框,但背景仍然不是圆角,所以它超出了边框。 我尝试过填充,但不起作用(小填充没有任何效果,大填充缺少我的背景)。 有什么想法吗

编辑: 我有一个带有扩展QGraphicsView(在设计器中创建)的小部件窗口。我使用代码创建QGraphChisScene。 然后我将pixmap和我的按钮(类按钮继承QPushButton)添加到该场景中

我得到了这样的东西:
我使用这个CSS,它适合我


不要使用pixmap,直接从CSS中使用它,正如这里指定的:

我必须使用pixmap,因为它是整个窗口的背景,而不是按钮。
我解决了我的问题:我更改了一些内容,我应该将qGraphicsView设置为button的父级,只有这样它才能正常工作。

请在将来将标题作为一个具体问题来表述。这有助于搜索引擎,以及未来和当前的访问者准确地查找和使用您的问题。对不起,我在搜索类似问题后忘记了更改它