如何使QComboBox弹出窗口向上? [英] How to make QComboBox popup upwards?

查看:884
本文介绍了如何使QComboBox弹出窗口向上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 QComboBox 派生的类位于(可见)屏幕底端的 QGraphicsScene 中,但它向下弹出,因此看不见.

(如何)可以强制弹出窗口打开上方窗口小部件?

我尝试过像这样重新实现 showPopup :

void MyComboBox::showPopup()
{
     QAbstractItemView *popupView = view();
     popupView->move(0,-100);
     //popupView->window->move(0,-100);
     QComboBox::showPopup();
}

结果是,内容似乎已转移,但底层的弹出对象未转移. 我认为有可能找到一种具有如下所示样式的解决方案 这篇文章,但我在这里找不到任何可能有用的样式控件.我对C ++和Qt都很陌生,所以我可能缺少明显的东西.

在此问题上的任何帮助,我将不胜感激!

最诚挚的问候,

塞巴斯蒂安

解决方案

使用找到的信息在这里,我能够通过以下方式完成操作:

void SteuerQComboBox::showPopup() {
    QComboBox::showPopup();
    QWidget *popup = this->findChild<QFrame*>(); 
    popup->move(popup->x(),popup->y()-this->height()-popup->height());
}

请注意,将基类称为" showPopup " 第一至关重要.

感谢所有阅读我的问题并正在思考的人!

my QComboBox-derived class lives in a QGraphicsScene at the bottom end of the (visible) screen - but it pops up downwards, thus out of view.

(How) is it possible to force the popup to open above the widget?

I've tried re-implementing showPopup like this:

void MyComboBox::showPopup()
{
     QAbstractItemView *popupView = view();
     popupView->move(0,-100);
     //popupView->window->move(0,-100);
     QComboBox::showPopup();
}

The result is, that the content seems to be shifted, but not the underlying popup object. I think it might be possible to find a solution with styles as indicated in this article, but I can't find any Styles control that might be helpful here. I am rather new to C++ as well as Qt, so I might be missing something obvious.

I'd appreciate any help on this matter!

Best regards,

Sebastian

解决方案

With the information found here, I was able to get it done this way:

void SteuerQComboBox::showPopup() {
    QComboBox::showPopup();
    QWidget *popup = this->findChild<QFrame*>(); 
    popup->move(popup->x(),popup->y()-this->height()-popup->height());
}

Note that it's crucially important to call the base classes "showPopup" first.

Thanks to everybody who was reading my question and thinking about it!

这篇关于如何使QComboBox弹出窗口向上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆