Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QToolButton with margin is clickable
QtWS25 Last Chance

QToolButton with margin is clickable

Scheduled Pinned Locked Moved Unsolved General and Desktop
marginstylesheet
6 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    leonardo M B
    wrote on last edited by leonardo M B
    #1

    So I Adjusted the margin-left with:

    _ui.myToolBar->setStyleSheet("QToolButton { width: 37px; height: 37px; padding: 0px; border: 0px; margin-left: 16px;}");
    

    But this happens: When I put the mouse in the black area:
    555875e5-cd0d-4e5f-bde6-df96f39538f7-image.png

    The button enters a hover event and I can Click and perform the actions. I Thought that margin-areas were not clickable, How can I avoid this behavior?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Toolbar does some funky stuff and basically adds this margin to the toolbutton, but the mouse events are handled on the layout item area, which contains that margin.
      To space items on a toolbar set spacing value for it instead of margins on individual items i.e.

      _ui.myToolBar->setStyleSheet("QToolBar { spacing: 16px; }");
      
      L 1 Reply Last reply
      3
      • Chris KawaC Chris Kawa

        Toolbar does some funky stuff and basically adds this margin to the toolbutton, but the mouse events are handled on the layout item area, which contains that margin.
        To space items on a toolbar set spacing value for it instead of margins on individual items i.e.

        _ui.myToolBar->setStyleSheet("QToolBar { spacing: 16px; }");
        
        L Offline
        L Offline
        leonardo M B
        wrote on last edited by leonardo M B
        #3

        @Chris-Kawa For some reason spacing is not working for me..............
        Is there something wrong about the code? Or maybe some other stylesheet is influencing this behavior?

        _ui.otherBar->setStyleSheet("QToolButton { width: 37px; height: 37px; border: 0px; padding: 0px; } QToolBar::separator {background-color: black; margin-top: 15px; margin-bottom: 15px;} QToolBar {background-color: green; spacing: 16px;}");
        
        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Works for me. What platform are you on? Have you tried stepping into the layout code to see what happens when the item geometry is calculated?

          L 1 Reply Last reply
          0
          • Chris KawaC Chris Kawa

            Works for me. What platform are you on? Have you tried stepping into the layout code to see what happens when the item geometry is calculated?

            L Offline
            L Offline
            leonardo M B
            wrote on last edited by leonardo M B
            #5

            @Chris-Kawa I Have a class mainWindow, thats where I Have:

            _ui.otherBar->setStyleSheet("QToolButton { width: 37px; height: 37px; border: 0px; padding: 0px; } QToolBar::separator {background-color: black; margin-top: 15px; margin-bottom: 15px;} QToolBar {background-color: green; spacing: 16px;}");
            

            And In My QApplication I set a Stylesheet in the following order:

            QFile css(QStringLiteral(":/stylesheet/my.css"));
            css.open(QFile::ReadOnly | QFile::Text);
            app.setStyleSheet(css.readAll());
            css.close();
            
            MainWindow *mainWindow = new MainWindow;
            

            If I bring the mainWindow declaration to the top of the code, it works fine, but if it is left after the QAplicattion::setStylesheet, the property spacing doesn't work.

            1 Reply Last reply
            0
            • Chris KawaC Offline
              Chris KawaC Offline
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Since it changes geometry of the items after maybe it's another quirk. Try calling QStyle::unpolish and then QStyle::polish() with the toolbar.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved