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 menu-button position
Forum Updated to NodeBB v4.3 + New Features

QToolButton menu-button position

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtoolbuttonstylesheetsmenu button
1 Posts 1 Posters 538 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    awats979
    wrote on 17 May 2023, 20:48 last edited by awats979
    #1

    Hi, I would expect this menu-button to appear below the QToolButton, however it always appears to the right. How do I specify the location of the menu-button relative to the QToolButton with stylesheets?

    #include "mainwindow.h"
    #include "qtoolbutton.h"
    #include "qmenu.h"
    #include "qgridlayout.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        QWidget wig;
        QGridLayout* layout = new QGridLayout();
    
        QString style =
        "QToolButton[popupMode=\"1\"]{"
        "   background: pink;"
        "   }"
        "QToolButton::menu-button {"
        "    subcontrol-position: bottom;"
        "    subcontrol-origin: margin;"
        "    background: red;"
        "}";
    
        a.setStyleSheet(style);
    
        QMenu *menu = new QMenu();
        QAction *testAction = new QAction("test menu item");
        menu->addAction(testAction);
    
        QToolButton* toolBtn = new QToolButton();
        toolBtn->setText("Tool Button");
        toolBtn->setMenu(menu);
        toolBtn->setPopupMode(QToolButton::MenuButtonPopup);
    
        layout->addWidget(toolBtn);
        wig.setLayout(layout);
        w.setCentralWidget(&wig);
        w.show();
        return a.exec();
    }
    

    a6cd8593-ce70-444d-8922-19b9acbbb52d-image.png

    1 Reply Last reply
    1

    1/1

    17 May 2023, 20:48

    • Login

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