Results 1 to 5 of 5

Thread: Tracking separators in a menu (insertSeparator)

  1. #1
    Join Date
    Jan 2006
    Posts
    17
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Tracking separators in a menu (insertSeparator)

    (Qt 3)
    In the QMenuData class there is an "int" return value when using the insertSeparator method but the text doesn't explain what exactly it is returning ...?

    Here is the text:
    int QMenuData::insertSeparator ( int index = -1 )

    Inserts a separator at position index. The separator becomes the last menu item if index is negative.
    In a popup menu a ......etc


    What is this int value? The reason I ask is that I need to track separators and remove them if they are side by side in the menu (later on in the code I hide certain menu items according to the user logged in). I thought I could use this int value to track the separators but the values are odd (like -36 for example).

    Anyone try to track separators in a menu (I need to be able to track them like regular menu items)?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Tracking separators in a menu (insertSeparator)

    Maybe success == 0, failure < 0?

    You should check the sources of Qt. You'll probably find your answer easily there.

  3. #3
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Tracking separators in a menu (insertSeparator)

    I believe it returns a menu id, like
    int QMenuData::insertItem().

    You can use int QMenuData::removeItem(). To remove separators using this id.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Tracking separators in a menu (insertSeparator)

    Quote Originally Posted by Chicken Blood Machine
    I believe it returns a menu id, like
    int QMenuData::insertItem().
    That was my first thought too, but the poster said these numbers are negative, which is unlikely for an id.

  5. #5
    Join Date
    Jan 2006
    Posts
    17
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Tracking separators in a menu (insertSeparator)

    I don't know why separators are treated so differently than other menu objects but I am having difficulty removing separators that are side by side. Maybe someone can check my logic found below.

    PreCondition: Menus and separators have already been added, the weird number that adding a separator returns is stored in a vector called separatorVec, some menu's have been hidden per the users login permissions.

    What I want to do: Remove spare separators that are now stacked on top of each other so that the logged in user has no indication that menu items are missing. The code below is JUST going to check if the separator is the first visible item in them menu and remove it if it is. (it doesn't work, the code never removes a separator even if 2 separators are at the very top of the menu)

    Qt Code:
    1. void MainScreenView::SeparatorRemovalHelper(QPopupMenu *theMenu)
    2. {
    3. //check the menu for separator weirdness
    4. for (int i = 0; i < theMenu->count(); i++)
    5. {
    6. int currId = theMenu->idAt(i);
    7. //loop the separatorVec and compare the funky ID's
    8. for (int k = 0; k < separatorVec.size(); k++)
    9. {
    10. int sepId = separatorVec[k];
    11.  
    12. if (currId == sepId)
    13. {
    14. //found a separator
    15. //make sure its not the first visible item in the menu
    16. //work backwards from i position to test for menu
    17. //items that are visible
    18. bool foundVisible = false;
    19. int j=0;
    20. for (j = i; j != 0; j--)
    21. {
    22. if (theMenu->isItemVisible(j-1) == true)
    23. {
    24. foundVisible = true;
    25. break;
    26. }
    27. }
    28. //if didn't find a visible item from i position back
    29. //then remove it
    30. if (foundVisible == false)
    31. {
    32. theMenu->removeItem(sepId);
    33. break;
    34. }
    35. }//end IF currId == sepId
    36. }//end for int k = 0
    37. }
    38. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by PrimeCP; 25th January 2006 at 18:44.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.