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 red box trying double click, , think should returning -1. returns tab index when double click tab, know working correctly. applicationwindow

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

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

run code , add 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. , try use 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 red box isn't tabbar

to add tab, can provide special button or use tabbardoubleclicked signal too, use count() method know, how 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 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 catch signal. when index equals -1, can create new tab(or open dialog let 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:

enter image description here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -