Unsolved QToolButton bottom left down arrow
-
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.
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.
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
-
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; }
-
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
-
I think it should work with:
QToolButton::down-arrow {
image: none;
background-color: red;
}in your stylesheet