如何设置文本下面的QToolButton在QT不低于图标
How to set text below the QToolButton in QT not below the icon
我使用QToolButton并设置图标。现在我想要文本"below the QToolButton"
, "Not below the icon"
。有没有办法在c++中实现这一点,QT在Linux中?
我发现自己在不久前为嵌入式Linux系统开发应用程序时也处于同样的位置。
我还没有找到一个直接的解决方案(我正在寻找一种用CSS实现它的方法)。
我最后做的是创建一个新的QWidget(使用设计器)。然后将按钮放入其中,并在其下方放置QLabel。
然后添加一个简单的静态函数static void wdgCustomButton::create(const QString iconPath, const QString text)
{
// create a new button here, create some modification functions for
// text, image and optionally QStyleSheets.
// Call those here (pass the arguments)
// Then return the button
// pseudo code, (not tested):
wdgCustomButton button = new wdgCustomButton( /* could pass a parent */ );
button->setIcon( iconPath ); // function simply calls the ui->button->setIcon
button->setText( text ); // function simply calls the ui->label->setText
return button;
}
然后使用代码将这些新的QWidgets添加到您的面板(也许有人知道如何在默认工具栏中获得它,但我自己还没有搜索过,因为我从来没有需要过它)。
this->menuButtons[menuBtnsCount] = wdgCustomButton::create( ":/Images/Warning.png", "Delete everything" );
this->menuButtons[menuBtnsCount]->setGeometry( QRect( /* size and position here */ ) );
this->menuButtons[menuBtnsCount]->show();
我希望这可能会给你一个简单的方法来修复它的想法!
编辑:抱歉,我忘了添加click事件。点击事件是我制作QWidget的主要原因!我只是使用了连接功能[我相信整个按钮像:connect(this->menuButtons[0],…]
相关文章:
- Qt VTK交互风格的信号到小部件
- QT在错误的班级中寻找空位
- 如何在选项卡视图Qt中设置一个新项目,并保存以前的项目
- 如何在Qt窗口小部件中使用QStringView(或QStringRef)
- 如何在Qt C++中更改光标
- 如何在MS Visual Studio 2019中运行QT UI
- QT通过C++添加映射QML项目
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 如何将点击的信号和插槽添加到qt中的自定义按钮中
- Qt C++静态thread_local QNetworkAccessManager是线程应用程序的好选择吗
- 使用Qt C++计算类似Git的SHA1哈希
- Qt focusObjectChanged example?
- 如何在cpp文件之间切换窗口?在Qt中
- Qt和C++:将QLineEdit添加到QTabWidget中
- 从数据库实时显示QT c++中的数据
- Qt Quick-如何仅从c++代码与qml属性交互
- 无法使用Qt Creator在Windows中构建yaml-cpp
- 如何在Qt中取消捕获字符串
- 无法增加 QToolButton 的大小(按钮样式设置为 Qt::ToolButtonTextBesideIcon)
- 如何设置文本下面的QToolButton在QT不低于图标