qmenu

Remove icon space from QMenu

微笑、不失礼 提交于 2020-05-08 03:15:47
问题 I'm working on a Qt application (in C++). Without appyling any styles, my menu looks like this: I'd like it to look like this: How do I achieve this? Either using qss, or programmatically? I already tried this, without success: menu->addAction(tr("Add"), this, SLOT(CreateNewWaypoint()))->setIconVisibleInMenu(false); Answers for both Qt4.8 and Qt5 are needed to get the full bounty! 回答1: One way to solve the problem is to use QProxyStyle: customstyle.h #ifndef CUSTOMSTYLE_H #define CUSTOMSTYLE

Right justify QKeySequence in PyQt QAction Menu

泪湿孤枕 提交于 2020-01-05 12:16:51
问题 How I can right justify the QKeySequence in PyQt5? copy_absolute_path_action = ( create_action(self, _("Copy Absolute Path"), QKeySequence( get_shortcut('explorer', 'copy absolute path')), triggered=self.copy_absolute_path)) copy_relative_path_action = ( create_action(self, _("Copy Relative Path"), QKeySequence( get_shortcut('explorer', 'copy relative path')), triggered=self.copy_relative_path)) copy_file_clipboard_action = ( create_action(self, _("Copy File to Clipboard"), QKeySequence(get

How to add a list of QActions to a QMenu and handle them with a single slot?

左心房为你撑大大i 提交于 2019-12-29 06:47:10
问题 First, I have a list of QWidget s that I won't know the length of until runtime. I then create a QListWidget where I show them and when someone clicks them I use the signal currentItemChanged(QListWidgetItem*, QListWidgetItem*) to catch it and get the clicked item's index. Now I want to do a similar thing in the QMenu . I will know the list when the QMenu and its actions get built, but I won't be able to hard code this. How can I create actions, catch their signals and connect them to the

Fill QMenu with an enum

Deadly 提交于 2019-12-25 16:54:11
问题 I have a few struct s with enum and std::string and I used to fill QComboBox es with them using a for() loop. Something like this: struct Struct { enum Enum { ENTRY1, ENTRY2, ... ENTRY_ALL }; std::string names[ENTRY_ALL] {...}; }; for(int i=0; i<Struct::ENTRY_ALL; ++i) comboBox->insertItem(i, names[i].c_str()); It worked, but given recent advances I need more entries, more struct s, more combo boxes, and it gets ugly, so I decided I'd switch to a QMenu . Looking at the documentation and the

Passing argument to PyQt SIGNAL connection

喜你入骨 提交于 2019-12-24 04:07:12
问题 Is it possible to pass an argument to PyQt4 Signal connections? In my case I have n buttons with set the same menu dinamically created on the interface, depending on user's input: for j in range(0, len(self.InputList)): arrow = QtGui.QPushButton(Form) arrow.setGeometry(QtCore.QRect(350, 40*(j+3)+15, 19, 23)) menu = QtGui.QMenu(Form) for element in SomeList: cb = QtGui.QRadioButton(element,menu) ca = QtGui.QWidgetAction(menu) ca.setDefaultWidget(cb) QtCore.QObject.connect(cb,QtCore.SIGNAL(

Custom Qt QMenu

烈酒焚心 提交于 2019-12-22 04:16:13
问题 Is there a way in Qt to add a layout or widgets to a QMenu to create a custom menu? The example below (left) is what I have, and I'd like to aim for something similar to the mock-up on the right, by adding non-menu widgets. If it can't be done by QMenu , are there guides to produce similar results (perhaps by having a more standard widget act as a context menu) anywhere? 回答1: Sure there is! In Qt, if there is a a will there is a way. You will probably need to make your own class that uses

Qt: Change application QMenuBar contents on Mac OS X

江枫思渺然 提交于 2019-12-21 22:59:54
问题 My application uses a QTabWidget for multiple 'pages', where the top-level menu changes depending on what page the user is on. My issue is that attempting to re-create the contents of the menu bar results in major display issues. It works as expected with the first and third style (haven't tested second, but I'd rather not use that style) on all platforms except for Mac OS X. The first menu is created in the way I create most in the application, and they receive the correct title, but

Qt UI testing: How to simulate a click on a QMenuBar item using QTest?

左心房为你撑大大i 提交于 2019-12-20 23:53:34
问题 I am trying to simulate a mouse click on a QMenu item from a QMenuBar, for example clicking on "Save As" QAction using the QTestLib framework. I am triyng this under Windows XP 32 bit and Qt 5.0.2. Any Ideas? 回答1: Probably this question is not relevant for question owner, but I suppose it could be helpful for others. Unlike QToolBar , QMenu doesn't have method widgetForAction . I found a simple workaround for this case. Try popup menu with QTest::mouseClick if nothing happens try to use QTest

How to pass a QString to a Qt slot from a QMenu via QSignalMapper or otherwise

独自空忆成欢 提交于 2019-12-19 18:27:01
问题 I have a QMenu with many submenus. These are dynamically created i.e. the names menus come from a db and created in a loop. Now i wanted to fire the same slot triggered() or similar when a menu is clicked, but i needed the QString menu name to be passed to slot so i could perform menu specific actions. I have tried this i.e. passing a QAction * to the triggered event and used setData but i am getting the run time error. object::connect: No such signal QAction::triggered(QAction *) for(int j=0

QTooltip for QActions in QMenu

半世苍凉 提交于 2019-12-13 11:57:30
问题 I want to be able to show ToolTips for QMenu items ( QAction s). The best I have achieved is to connect the hovered signal of the QAction to a QTooltip show: connect(action, &QAction::hovered, [=]{ QToolTip::showText(QCursor::pos(), text, this); }); The problem is that sometimes the program will position the tooltip below the menu, specially when changing menus. Is there any way to force the tooltip to show on top? 回答1: You can subclass QMenu and reimplementing QMenu::event() to intercept the