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 bottom left down arrow

QToolButton bottom left down arrow

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 3.9k 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.
  • D Offline
    D Offline
    DaStroe
    wrote on last edited by DaStroe
    #1

    Hey folks,

    i want to create a QToolButton with instant popup and down arrow alongside button text. It is working for me by setting the ToolButtonStyle and DownArrow. The image below shows the tool button.

    Image 1

    However, when i add an Action to the tool button, another down arrow in the lower right corner appears like presented by the image below.

    alt text

    I do not want that arrow. Is there any way to get rid of the down arrow in the lower right corner?

    Minimal example

    main.cpp

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        MainWindow w;
        w.show();
    
        return a.exec();
    }
    

    mainwindow.h

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    
    namespace Ui {
    class MainWindow;
    }
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        explicit MainWindow(QWidget *parent = 0);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
        QAction* myDummyAction;
        QMenu* myMenu;
    };
    
    #endif // MAINWINDOW_H
    

    mainwindow.cpp

    #include"mainwindow.h"
    #include"ui_mainwindow.h"
    
    #include<QAction>
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        myDummyAction = new QAction("dummy action", this);
    
        ui->setupUi(this);
    
        ui->toolButton->addAction(myDummyAction);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    

    mainwindow.ui

    <?xml version="1.0" encoding="UTF-8"?>
    <ui version="4.0">
     <class>MainWindow</class>
     <widget class="QMainWindow" name="MainWindow">
      <property name="geometry">
       <rect>
        <x>0</x>
        <y>0</y>
        <width>143</width>
        <height>80</height>
       </rect>
      </property>
      <property name="windowTitle">
       <string>MainWindow</string>
      </property>
      <widget class="QWidget" name="centralWidget">
       <property name="cursor">
        <cursorShape>SizeHorCursor</cursorShape>
       </property>
       <property name="focusPolicy">
        <enum>Qt::NoFocus</enum>
       </property>
       <layout class="QVBoxLayout" name="verticalLayout_2">
        <item>
         <widget class="QToolButton" name="toolButton">
          <property name="cursor">
           <cursorShape>PointingHandCursor</cursorShape>
          </property>
          <property name="text">
           <string>MyToolButton</string>
          </property>
          <property name="popupMode">
           <enum>QToolButton::InstantPopup</enum>
          </property>
          <property name="toolButtonStyle">
           <enum>Qt::ToolButtonTextBesideIcon</enum>
          </property>
          <property name="autoRaise">
           <bool>true</bool>
          </property>
          <property name="arrowType">
           <enum>Qt::DownArrow</enum>
          </property>
         </widget>
        </item>
       </layout>
      </widget>
      <widget class="QToolBar" name="mainToolBar">
       <attribute name="toolBarArea">
        <enum>TopToolBarArea</enum>
       </attribute>
       <attribute name="toolBarBreak">
        <bool>false</bool>
       </attribute>
      </widget>
      <widget class="QStatusBar" name="statusBar"/>
     </widget>
     <layoutdefault spacing="6" margin="11"/>
     <resources/>
     <connections/>
    </ui>
    
    

    Regards

    DaStroe

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mostefa
      wrote on last edited by
      #2

      Hi @DaStroe

      What about using setDefaultAction instead of addAction ?

      Your cpp will look to something like this:

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      
      #include <QDebug>
      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          myDummyAction = new QAction("dummy action", this);
      
          ui->toolButton->setDefaultAction(myDummyAction);//use setDefaultAction instead of addAction
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      1 Reply Last reply
      0
      • D Offline
        D Offline
        DaStroe
        wrote on last edited by
        #3

        Hi mostefa

        Using setDefaultAction removes the arrow in the lower right. However, i want to create a drop down menu with multiple actions, which pops up on click. The setDefaultAction method does not create such a menu.

        Is there any way to have a drop down menu in QToolButton without having the down arrow in the lower right corner?

        Regards

        DaStroe

        1 Reply Last reply
        0
        • T Offline
          T Offline
          T_A_
          wrote on last edited by
          #4

          I think it should work with:

          QToolButton::down-arrow {
          image: none;
          background-color: red;
          }

          in your stylesheet

          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