0

I wrote a minimal example which has a sidebar which contains a QToolButton on it. I set setAutoRaise(true) for the QToolButton, so when hover on it, the button will raise. But currently I have a minor issue. As you can see from the picture below, when hover on the button, the border on the right and left are not fully take the whole screen.
Here is how that looks like:
enter image description here

And this example what I want to button to look like:
enter image description here

And here is my code:

sidebarDock = new QDockWidget(this);
addDockWidget(Qt::LeftDockWidgetArea, sidebarDock);

//hide dock widget title bar
QWidget *titleBarWidget = new QWidget(sidebarDock);
sidebarDock->setTitleBarWidget(titleBarWidget);
sidebarDock->titleBarWidget()->hide();

dockWidget = new QWidget(sidebarDock);
dockWidget->setObjectName("DockWidget");
dockWidget->setStyleSheet("#DockWidget { background-color: #F7DC6F; }");
dockVLayout = new QVBoxLayout(dockWidget);
overviewBtn = new QToolButton(dockWidget);
overviewBtn->setAutoRaise(true);
overviewBtn->setIcon(QIcon(":/Icons/overview.png"));
overviewBtn->setText("Overview");
overviewBtn->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
dockVLayout->addWidget(overviewBtn);
dockWidget->setLayout(dockVLayout);
sidebarDock->setWidget(dockWidget);

So can someone tell me which part I missed to set the QQToolButton right and left border completely to side? Or are there some better ways to achieve this? Thanks.

Theodore Tang
  • 831
  • 2
  • 21
  • 42
  • Maybe you need to 1. Remove margins, 2. Create bigger image – Serhiy May 10 '18 at 06:21
  • @Serhiy 1. I tried to set both button and layout margin to 0 with `setContentsMargins(0, 0, 0, 0)`, it still remains the same; 2. I tried using a bigger image, but the margin is still there. Are there some other ways? – Theodore Tang May 10 '18 at 06:26

1 Answers1

0

Now I solved this problem.
Just need to add one line to the code snippet to set the layout's margin to 0, using: dockVLayout->setMargin(0)

Theodore Tang
  • 831
  • 2
  • 21
  • 42