Гость
Целевая тема:
Создать новую тему:
Автор:
Форумы / C++ [игнор отключен] [закрыт для гостей] / QMenu + QWidgetAction / 1 сообщений из 1, страница 1 из 1
14.07.2013, 17:09
    #38330589
mir_sly2
Гость
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
QMenu + QWidgetAction
Есть QTableView, по нажатию любой клавиши появляется popup QMenu с QLineEdit

Размер QMenu меняется на нужный, а размер QLineEdit - фиксированный.

Как его изменить?

Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
class ItemBrandView : public QWidget
{
    Q_OBJECT

    protected:
        bool eventFilter(QObject *watched, QEvent *event);

    private:
        QTableView* table;

        QMenu* popupMenu;
        QLineEdit* finder;

...
};

void ItemBrandView::init()
{
...

    table = new QTableView();
    table->installEventFilter(this);

...

    finder = new QLineEdit(this);
    popupMenu = new QMenu(this);

    QWidgetAction* wFinder = new QWidgetAction(popupMenu);
    wFinder->setDefaultWidget(finder);

    popupMenu->addAction(wFinder);

};

bool ItemBrandView::eventFilter(QObject *watched, QEvent *event)
{
    if(watched == table)
    {
        if(event->type() == QEvent::KeyPress)
        {
            QKeyEvent* keyEvent = (QKeyEvent* ) event;

            if(keyEvent->key() == Qt::Key_Space)
            {
                QModelIndex currentIndex = table->currentIndex();

                int x = table->columnViewportPosition(currentIndex.column());
                int y = table->rowViewportPosition(currentIndex.row());
                int columnWidth = table->columnWidth(currentIndex.column());

                popupMenu->popup(QPoint(table->horizontalHeader()->mapToGlobal(QPoint(x, y)).x(),
                                        table->horizontalHeader()->mapToGlobal(QPoint(x, y)).y()));
                popupMenu->resize(columnWidth, 20);

                return true;
            }
        }

        return false;
    }

    return QWidget::eventFilter(watched, event);
}
...
Рейтинг: 0 / 0
Форумы / C++ [игнор отключен] [закрыт для гостей] / QMenu + QWidgetAction / 1 сообщений из 1, страница 1 из 1
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]