| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 3 | |
Hi, I'm trying to write an application that presents a popup menu that mirrors a portion of the file system. As a first-pass attempt I've written a function that recursively scans the file system and builds the QMenu as it goes. This works fine for small sections of the filesystem, but larger scans can take a long time (I tried scanning / - it took 15-20 minutes to complete!) What I'm looking for is a method of populating only as much of the menu as I need - So, when the menu is first shown, I'd populate it with the top-level folder entries. When the user hovers over a sub-folder item, I'd populate the menu with the next folder contents. This way, I can show any part of the file system without any performance penalty. I tried doing this using the hovered() signal, but the problem is that a) It's difficult to work out exactly which subfolder item is being hovered, and b) I'm not sure I can make subfolder items appear as sub-menus before I've populated them. Does anyone have any advice on this topic? Cheers, -- [ signature omitted ]
Am Dienstag, 18. März 2008 schrieb Thomas Richards: > I'm trying to write an application that presents a popup menu that > mirrors a portion of the file system. As a first-pass attempt I've > written a function that recursively scans the file system and builds the > QMenu as it goes. This works fine for small sections of the filesystem, > but larger scans can take a long time (I tried scanning / - it took > 15-20 minutes to complete!) > What I'm looking for is a method of populating only as much of the menu > as I need - So, when the menu is first shown, I'd populate it with the > top-level folder entries. When the user hovers over a sub-folder item, > I'd populate the menu with the next folder contents. This way, I can > show any part of the file system without any performance penalty. > I tried doing this using the hovered() signal, but the problem is that > a) It's difficult to work out exactly which subfolder item is being > hovered, and b) I'm not sure I can make subfolder items appear as > sub-menus before I've populated them. > Does anyone have any advice on this topic? Maybe implement it as a View? As far as I know, the Models representing the directory-structure already do what you want (ie. scan dirs only when needed), you only need a view to access that information. And implementing a view that is in fact a QMenu seems to call for an abstract view-baseclass that is not a qwidget. :-) Arnold PS: As this is my first mail to this list: I use Qt since 1.4something, in fact I learned OOP through the Qt-tutorials. But I didn't subscribe to this list until last Friday... -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
On Tuesday 18 March 2008 10:40:25 Thomas Richards wrote: > Hi, > > I'm trying to write an application that presents a popup menu that > mirrors a portion of the file system. As a first-pass attempt I've > written a function that recursively scans the file system and builds the > QMenu as it goes. This works fine for small sections of the filesystem, > but larger scans can take a long time (I tried scanning / - it took > 15-20 minutes to complete!) In the demo browser I wrote a QMenu subclass that take a QAbstractItemModel and dynamically populates from the model. This or a similar bit of code could be used in conjuntion with the QDirModel. -Benjamin Meyer -- [ signature omitted ]
> > In the demo browser I wrote a QMenu subclass that take a > QAbstractItemModel > and dynamically populates from the model. This or a similar bit of code > could be used in conjuntion with the QDirModel. > > -Benjamin Meyer > That sounds like what I need, thanks! -- [ signature omitted ]
Hi List, > -----Original Message----- > From: Benjamin Meyer [mailto:bmeyer@xxxxxxxxxxxxx] > > In the demo browser I wrote a QMenu subclass that take a > QAbstractItemModel > and dynamically populates from the model. This or a similar bit of code > could be used in conjuntion with the QDirModel. > Hi Benjamin, I'm using a modified version of your menu code in my application. It works really well- the one problem I have is that once the menu has been run using exec() or popup(), the only way to close the menu under windows is to click on a menu item. If you click outside the menu window it doesn't die.. which is really annoying. I checked, and the same behavior is present in the "virgin" source form the latest Qt snapshot. However, under Linux this seems to work just fine. Am I missing something here? Any suggestions would be greatly appreciated. Cheers, -- [ signature omitted ]
Okay, a bit more careful investigation shows something a little bit more basic...
First, it seems I was mistaken - this problem happens with even a vanilla QMenu object.
My application is very simple. I have a QSystemTrayIcon, and I have connected the activated(reason) signal to a slot of my own. In that slot, I launch a QMenu if the reason was "QSystemTrayIcon::Trigger".
I launch the menu using exec(). I wrote some test code, like so:
QMenu menu;
for (int i = 0; i < 50; i++)
{
menu.addAction(QString("Item %1").arg(i));
}
menu.exec(QCursor::pos());
Under Linux, this works fine. However, under Windows XP, the only way to get the menu to dissapear after it's been launched is to click on an item inside the menu. Clicking on the desktop or another application does not destroy the menu.
I tried overriding the QWidget::focusOutEvent, but it never gets called - and it seems that perhaps it's intended to notify when your widget loses focus to anotehr widget in the same app, rather than your entire application losing focus.
Is this a bug? It seems to me that at the very least the behavior between Linux and Windows should be the same.
Cheers,