c++ - Why won't QTabBar's tabBarDoubleClicked(int) handle double clicking the tab bar? -



c++ - Why won't QTabBar's tabBarDoubleClicked(int) handle double clicking the tab bar? -

this driving me nuts. qtabbar's documentation says that:

void qtabbar::tabbardoubleclicked(int index) [signal]

this signal emitted when user double clicks on tab @ index. index refers tab clicked, or -1 if no tab under cursor.

so, when double click tab bar, shouldn't returning -1?

just clear, bit in reddish box trying double click, , think should returning -1. returns tab index when double click tab, know working correctly.

but shouldn't bit in reddish box still technically tab bar? or tab bar expand tabs added? if so, there way create expand fill window horizontally?

i'm trying implement adding tab on double clicking tab bar; there way should going this?

run code , add together bar.

void mainwindow::on_tabwidget_tabbardoubleclicked(int index) { qdebug() << index << ui->tabwidget->tabbar()->geometry(); }

you see this:

0 qrect(0,0 288x29) 2 qrect(0,0 288x29) ("g:/x.txt", "g:/xx.txt", "") //something added 3 qrect(0,0 311x29) //width increased 5 qrect(0,0 311x29) 4 qrect(0,0 311x29)

as can width 311x29. , seek utilize this:

void mainwindow::on_tabwidget_tabbardoubleclicked(int index) { ui->tabwidget->removetab(index); qdebug() << index << ui->tabwidget->tabbar()->geometry(); }

result can this:

2 qrect(0,0 221x29) 2 qrect(0,0 154x29) 1 qrect(0,0 50x21) 0 qrect(0,0 0x0)

as can see, delete tabs , tabbar becomes smaller. tabbar resized automaticaly. area in reddish box isn't tabbar

to add together tab, can provide special button or utilize tabbardoubleclicked signal too, utilize count() method know, how much tabs in widget right now.

edit:

for example:

void mainwindow::on_tabwidget_tabbardoubleclicked(int index) { int height = ui->tabwidget->tabbar()->height(); ui->tabwidget->tabbar()->setgeometry(0,0,ui->tabwidget->geometry().width(), height); qdebug() << index << ui->tabwidget->tabbar()->geometry(); }

of course of study should setgeometry in place (in constructor maybe), did smaller code. tabbar bigger, there no changes in design or else. result:

2 qrect(0,0 311x29) 1 qrect(0,0 311x29) -1 qrect(0,0 311x29) -1 qrect(0,0 311x29)

as can see, -1 appears in output, appears when click on area there no tab(without setgeometry empty area), know can grab signal. when index equals -1, can create new tab(or open dialog allow user settings). think need.

another way:

qpushbutton *m_addbutton = new qpushbutton("+", this); qpushbutton *m_addbutton1 = new qpushbutton("-", this); m_addbutton->resize(15,15); m_addbutton1->resize(15,15); ui->tabwidget->tabbar()->settabbutton(0, qtabbar::rightside, m_addbutton); ui->tabwidget->tabbar()->settabbutton(0, qtabbar::leftside, m_addbutton1);

result:

c++ qt tabs

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -