如何在 Qt 中从 QToolBar 自定义 QToolButtons?
我有 QToolBar,上面有各种工具按钮。我想用一些简单的效果来自定义这些按钮,例如,应该看到按钮被按下,按下后应该更改其图标颜色或背景颜色等。
我尝试过,但没有成功。
_toolbar = new QToolBar;
_toolbar->setIconSize(QSize(35,35));
_toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
void createIcons()
{
_zoomInIcon = QIcon::fromTheme("zoom-in");
_zoomIn = new QAction(_zoomInIcon, "Zoom in", this);
// code for other icons
_toolbar->addAction(_zoomIn);
}
void myClass::ZoomIn()
{
_zoomIn->setCheckable(true);
//QToolButton:_zoomInIcon {background-color: red; }
//setStyleSheet('background-color: red;');
// other logic
}
此外,我正在使用Qt的默认图标 default-icons
但有些图标看起来不太好,特别是另存为
和另存为
。
那么除了上面的 Qt 链接之外,还有人知道更多默认图标吗?
谁能帮助我吗?
I am having QToolBar with various tool buttons on it. I want to customize those buttons with some simple effects like, it should be seen that button is pressed, after pressing it should change its icon color or background color etc.
I tried but I could not succeed.
_toolbar = new QToolBar;
_toolbar->setIconSize(QSize(35,35));
_toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
void createIcons()
{
_zoomInIcon = QIcon::fromTheme("zoom-in");
_zoomIn = new QAction(_zoomInIcon, "Zoom in", this);
// code for other icons
_toolbar->addAction(_zoomIn);
}
void myClass::ZoomIn()
{
_zoomIn->setCheckable(true);
//QToolButton:_zoomInIcon {background-color: red; }
//setStyleSheet('background-color: red;');
// other logic
}
Moreover I am using Qt's default icons from this default-icons
But some of the icons are not looking good specially save in
and save in as
.
So does any one knows more default icons apart from above link in Qt ?
Can anyone help me ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试如下所示(未测试)
,如果您的工具按钮没有菜单,您可以使用所有
QPushButton
样式。https://doc.qt.io/qt-5/ stylesheet-examples.html#customizing-qtoolbutton
Try something like below (not tested)
And you can use all
QPushButton
styles, if your tool button don't have a menu.https://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtoolbutton