Skip to content
QtWS25 Call for Papers
  • 0 Votes
    1 Posts
    116 Views
    No one has replied
  • 0 Votes
    3 Posts
    152 Views
    J

    @Jammin44fm

    OK I've solved it.

    The entire application has a Stylesheet applied, including settings for a QMenu, and QMenu item, with custom padding.
    By overriding the padding for the specific Menu in question I am setting the left padding to be the check icon size smaller than the normal padding size.
    Now when the menu is draw it is consistent in padding size with all other menu's.

    I still dont think i should have to do it this way, but it's working.

  • 0 Votes
    2 Posts
    202 Views
    T

    Your code should be fine. I think that the console.log() command is just in the wrong place.

    If I understood correctly, there are two user interactions involved. The first one is the click on the mouse area, which opens the menu. The second one is a click on a particular menu item, which actually sets the test value.

    Let's say you are performing the first interaction for the first time. At this point, the variable hasn't been set as you haven't clicked on a menu item yet. That is why the output of the console.log() command will be undefined. Then, you click on a menu item, which sets the variable. However, you won't be able to see the change until the menu is closed and you perform another click on the mouse area to make the menu pop up again.

    I think you'll see that your code works if you move the console.log() command to a different place:

    id: mouseArea1 property var testValue; onClicked: { menu.popup(); } Menu { id: menu MenuItem { text: "Option1" onTriggered: { mouseArea1.testValue= "25"; console.log(mouseArea1.testValue); } } }

    I don't know how many menu items you have in your actual code. Doing it this way, you'd need to add the same line to the onTriggered() signal handlers on all MenuItem instances, which could be annoying and bloat your code unnecessarily. So I'd suggest doing this instead:

    id: mouseArea1 property var testValue; onClicked: { menu.popup(); } Menu { id: menu MenuItem { text: "Option1" onTriggered: { mouseArea1.testValue= "25"; } } onClosed: { console.log(mouseArea1.testValue); } }

    I am assuming that the menu is closed once you hit a menu item. The code above logs the variable once the menu emits a closed() signal. I haven't tried it myself, but it should work. :)

  • 0 Votes
    7 Posts
    1k Views
    Chris KawaC

    Since applications using burger menus usually have a very distinctive style I didn't want to make any assumptions. The look of the menu is up to you to style, it only implements the functionality. Same goes for the burger icon, you can set it to whatever you want, either the one included in the project or your own. There's an example in the repo showing how to style it.

    As for actions - you can add an existing QAction or let the widget create one for you using any of the overloads of addMenuAction. In any case it returns a QAction* and you can connect to its triggered signal just as you would with any other action in the built-in Qt menus. Alternatively you can tag these actions in any way you want and only make a single connection to the BurgerMenu::triggered signal. You will get an action that was triggered as a parameter.
    One way to tag an action is by using QAction::setData or you can just store the action pointers somewhere when creating them and identify the action by the pointer, text, some property or whatever fits you.

    on_actionName_triggered() looks like a slot name created for the the auto-connection feature. If you want to use it you can do that too (although I wouldn't reccomend it). Just create your actions in the designer via its action editor and make your slots names match, just like you would with any normal menus/actions. The only caveat is that you need to manually add these actions to the menu from code, as there's no way to do that in the designer, but that's not a huge problem.

    So those are a couple of the most straightforward options out of couple more. It's deliberately left very flexible so you can use it however fits your overall application design best.

  • 0 Votes
    3 Posts
    573 Views
    M

    @Christian-Ehrlicher Thanks a lot, it is exactly what I was missing!

  • 0 Votes
    6 Posts
    585 Views
    T

    I took a look with the ListDLLs tool but couldn't actually find the plugin being used by the 32-bit version, maybe some other DLL is handling that? Anyway, my problem is now solved so I'll mark this topic as solved.

  • 0 Votes
    5 Posts
    618 Views
    X

    @LeLev Yes. I have created some menus statically, hide/show them manually. Thank you.

  • 0 Votes
    5 Posts
    621 Views
    mrjjM

    Hi
    I think you action runs out of scope

    it seems to be local variable
    QAction actions[11];

    and you take address of them so it does not copy but refernce inside the list
    listOfMenus[0].addAction(&actions[i]);

    but it looks to me like the actions[11]; lives in constructor and hence
    when Mainwindow is shown, they are all already deleted.

    Move the list to be a member of the class and see.

    Damn Pl45m4 beat me to it :)

  • 0 Votes
    4 Posts
    1k Views
    G

    @nland Did you ever figure this out?

  • 0 Votes
    3 Posts
    912 Views
    Renaud G.R

    @raven-worx Thanks, I will try that. I let you know if it works or not.

  • 0 Votes
    1 Posts
    610 Views
    No one has replied
  • 1 Votes
    5 Posts
    2k Views
    A

    Just changing MenuItem to CheckBox does the job. Menu stays as long as you clicking CheckBox items:

    Menu { CheckBox { text: "Item A" checkable: true checked: false onCheckedChanged: { console.debug("item A", checked) } } CheckBox { text: "Item B" checkable: true checked: false onCheckedChanged: { console.debug("item B", checked) } } }

    This topic is still high in search results, so I think it would be helpful to post correct answer. Despite question is old it is still useful.

  • 0 Votes
    2 Posts
    1k Views
    bchimpB

    ok this appears to be the same problem as this:
    https://forum.qt.io/topic/57647/qml-change-toolbar-color-one-style-property-only

    not really "solved", but at least some pointers in that previous post.

  • Switching menus

    Unsolved General and Desktop
    10
    0 Votes
    10 Posts
    7k Views
    kshegunovK

    @mandruk1331
    QDialog already provides all the signals (accepted() and rejected()) and slots (accept() and reject()) you'd need. You only need to call accept() when you've checked that the login is successful (meaning in the button slot). See my example in post #1 how to connect them! As to the login dialog implementation, something like this:

    class MLogIn : public QDialog { Q_OBJECT public: explicit MLogIn(QWidget *parent = 0); ~MLogIn(); private slots: void on_pushButton_2_clicked(); void on_pushButton_clicked(); private: Ui::MLogIn *ui; }; void MLogIn::on_pushButton_2_clicked() { //< Try logging the user in if (loginSuccessful) accept(); else QMessageBox::warning("No such user/password"); }
  • 0 Votes
    2 Posts
    2k Views
    SGaistS

    Hi,

    Please don't post the same question multiple times.

    Duplicate

    Closing this one.

  • 0 Votes
    4 Posts
    2k Views
    SGaistS

    No, that's the native OS X menu so you can't modify it. Again: use the Info.plist file, it's also explained in QMenuBar's documentation

  • 0 Votes
    10 Posts
    2k Views
    H

    @onek24

    For the benefit of anyone finding this post, I found a much simpler solution for attaching information to a menu action :

    void QAction::setData(const QVariant & userData) QVariant QAction::data() const

    I currently prefer it over the much heavier solution of implementing a custom QAction class.

  • 0 Votes
    2 Posts
    1k Views
    M

    Hi and welcome to devnet,

    2 things:

    Why this QString::fromUtf8(tr("XXX").toLatin1()) instead of tr("XXX") in QAction constructor ?? Why this mainWindow.menuBar()->addMenu(fileMenu); at the end ??
  • 0 Votes
    9 Posts
    3k Views
    SGaistS

    You're welcome !

    SInce everything is OK now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

    Also, while browsing the forum, consider up-voting the answers that helped you, it will make them easier to find for other users :)

  • 0 Votes
    1 Posts
    828 Views
    No one has replied