一、Qt Widgets 问题交流
1.QComboBox 下拉框设置透明样式不生效
Popup默认是有阴影的,也没法设置透明,可以给下拉框中ListView的parent设置透明效果:
combox->view()->parentWidget()->setWindowFlags(Qt::Popup|Qt::FramelessWindowHint);
combox->view()->parentWidget()->setAttribute(Qt::WA_TranslucentBackground);
这种方式也可以用在自定义的弹出窗口中,如把QWidget设置为Popup弹出的时候。
参考:https://blog.csdn.net/qq821181867/article/details/89639597
参考(未测试):https://blog.csdn.net/qq_43627385/article/details/103190377
(2021-11-28)对于一般的窗口如果设置为 Popup 想要去掉阴影,可以试试如下设置:
//setWindowFlag(Qt::FramelessWindowHint);
setWindowFlag(Qt::Popup);
setWindowFlag(Qt::NoDropShadowWindowHint);
2.QComboBox 下拉框给 Item 设置 padding-left 没效果
(问题版本:Qt5.12)
解决方法,设置了 border 后 padding-left 就生效了,如:
QComboBox QAbstractItemView::item {
height: 30px;
padding-left:10px;
border:1px solid transparent;
}
鼠标放到菜单时会触发StatusTip事件,而QMainWindow的event捕获并获取了其tip内容设置到状态栏:
#if QT_CONFIG(statustip)
case QEvent::StatusTip:
#if QT_CONFIG(statusbar)
if (QStatusBar *sb = d->layout->statusBar())
sb->showMessage(static_cast(event)->tip());
else
#endif
static_cast(event)->ignore();
return true;
#endif // QT_CONFIG(statustip)
所以,只需要重写下event函数,把StatusTip事件筛选掉就行了:
bool MainWindow::event(QEvent *event)
{
if(event->type()==QEvent::StatusTip){
qDebug()
关注
打赏