Why does my corner-widget not show up in QTabWidget?

Zciurus-Alt-Del

I have a QTabWidget and I would like to have two push buttons in the top right corner. I use this code to add a vertical Layout as the corner widget and add two buttons to it:

QWidget* cornerWidget = new QWidget();
QVBoxLayout* vbox = new QVBoxLayout();
QPushButton* button1 = new QPushButton("Button 1");
QPushButton* button2 = new QPushButton("Button 2");

vbox->addWidget(button1);
vbox->addWidget(button2);

ui->myTabWidget->setCornerWidget(cornerWidget);
cornerWidget->setLayout(vbox);
cornerWidget->show();

However when I run my program, no widget shows up in the top right corner at all.

If I use this simplified code to add only one push button, it works flawlessly and shows my button:

QPushButton* button1 = new QPushButton("Button 1")
ui->myTabWidget->setCornerWidget(button1);
scopchanov

Cause

The place for the corner widget is restricted. You use a vertical layout and its contents margins move the buttons down, out of sight.

Solution

Use a horizontal layout and set the contents margins to 0.

Example

Here is an example I wrote for you to demonstrate how the proposed solution could be implemented:

auto *cornerWidget = new QWidget(this);
auto *hbox = new QHBoxLayout(cornerWidget);
auto *button1 = new QPushButton(tr("Button 1"), this);
auto *button2 = new QPushButton(tr("Button 2"), this);

hbox->addWidget(button1);
hbox->addWidget(button2);
hbox->setContentsMargins(0, 0, 0, 0);

ui->myTabWidget->setCornerWidget(cornerWidget);

Result

The given example produces the following result:

Application window

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Accessing QTabWidget's widget

분류에서Dev

Why do some of my devices show up twice on my routers DHCP list?

분류에서Dev

Android GUI does not show up

분류에서Dev

Why won't my Android SDK Manager show up when invoked from Eclipse?

분류에서Dev

Why do '' show up as ' (HTML Entity?) in my charts.js.erb file?

분류에서Dev

Why does my Windows 7 computer freeze after waking up from Sleep?

분류에서Dev

Why does QuickCheck give up?

분류에서Dev

Why does my Swift button show a small blue square when tapped?

분류에서Dev

Why does my system show only 3.2 GiB of RAM when I definitely have 4.0 GiB

분류에서Dev

Why Won't the BG Colors Show Up?

분류에서Dev

why does my LAMP stack show my image when I navigate to it w/ a URL but not when I load it w/jQuery and PHP

분류에서Dev

Can I make some of my appointments not show up on the sidebar?

분류에서Dev

Why is my tlistbox requiring me to double up my ampersands?

분류에서Dev

Why awk does not show the correct record length?

분류에서Dev

Why do Chart Stacked Columns show up as thin lines?

분류에서Dev

Kendo UI batch edit grid DropDownList does not show up

분류에서Dev

Angular: Why does my formArray not validate or update?

분류에서Dev

Why does Doctrine QueryBuilder destroy my query?

분류에서Dev

Why does Outlook 2013 not send my email?

분류에서Dev

Why does my function print '0'?

분류에서Dev

Why does my linq to sql query fail?

분류에서Dev

Why does my ActionListener keep repeating?

분류에서Dev

Why does my JavaScript instances return the same?

분류에서Dev

Why does my blob not get sent?

분류에서Dev

Why does my bubble sort method not work?

분류에서Dev

Why does my wifi fail to stay connected?

분류에서Dev

Why does my wifi Internet intermittently disappear?

분류에서Dev

Why my cron Job does not work?

분류에서Dev

Why does my xdotool key command not work?

Related 관련 기사

  1. 1

    Accessing QTabWidget's widget

  2. 2

    Why do some of my devices show up twice on my routers DHCP list?

  3. 3

    Android GUI does not show up

  4. 4

    Why won't my Android SDK Manager show up when invoked from Eclipse?

  5. 5

    Why do '' show up as ' (HTML Entity?) in my charts.js.erb file?

  6. 6

    Why does my Windows 7 computer freeze after waking up from Sleep?

  7. 7

    Why does QuickCheck give up?

  8. 8

    Why does my Swift button show a small blue square when tapped?

  9. 9

    Why does my system show only 3.2 GiB of RAM when I definitely have 4.0 GiB

  10. 10

    Why Won't the BG Colors Show Up?

  11. 11

    why does my LAMP stack show my image when I navigate to it w/ a URL but not when I load it w/jQuery and PHP

  12. 12

    Can I make some of my appointments not show up on the sidebar?

  13. 13

    Why is my tlistbox requiring me to double up my ampersands?

  14. 14

    Why awk does not show the correct record length?

  15. 15

    Why do Chart Stacked Columns show up as thin lines?

  16. 16

    Kendo UI batch edit grid DropDownList does not show up

  17. 17

    Angular: Why does my formArray not validate or update?

  18. 18

    Why does Doctrine QueryBuilder destroy my query?

  19. 19

    Why does Outlook 2013 not send my email?

  20. 20

    Why does my function print '0'?

  21. 21

    Why does my linq to sql query fail?

  22. 22

    Why does my ActionListener keep repeating?

  23. 23

    Why does my JavaScript instances return the same?

  24. 24

    Why does my blob not get sent?

  25. 25

    Why does my bubble sort method not work?

  26. 26

    Why does my wifi fail to stay connected?

  27. 27

    Why does my wifi Internet intermittently disappear?

  28. 28

    Why my cron Job does not work?

  29. 29

    Why does my xdotool key command not work?

뜨겁다태그

보관