QStatusbar problem with insertWidget
-
"QStatusBar::insertWidget: Index out of range (1), appending widget" when will this warning is given ??...can somebosy guide me ??
EDIT: splitted this as it is an own topic, Gerolf
-
Hi,
can you please post some code, what you do? the error message without code is something like looking in a crystal ball to solve your problem.
One idea from the crystal ball:
you have not added any widgets and call QStatusBar::insertWidget(1, ...). This will fail, as index 0 is not filled.
-
@void IDT_MainWindow::on_treeWidgetDrives_itemClicked(QTreeWidgetItem* item, int column)
{
//QPalette *p = new QPalette();
//p->setColor(QPalette::Active,static_castQPalette::ColorRole(9),QColor(Qt:gray));ui->textEditDriverDetails->clear(); strDisk = item->text(column); //ui->textEditDriverDetails->setText(strDisk); QLabel *label1=new QLabel(); QLabel *label2=new QLabel(); QLabel *label3=new QLabel(); //QString strDir = ""; double dFree,dTotal; getFreeTotalSpace(strDisk,dTotal,dFree); QVariant var1( dTotal ); QVariant var2( dFree ); QString tmp1 = var1.toString(); QString tmp2 = var2.toString(); QFont texteditFont("Tokyo"); texteditFont.setPointSize(16); texteditFont.setBold(true); ui->textEditDriverDetails->setFont(texteditFont); //ui->textEditDriverDetails->setPalette(p); ui->textEditDriverDetails->insertPlainText("Drive Name : "+strDisk); ui->textEditDriverDetails->insertPlainText("\n\n\n"); ui->textEditDriverDetails->insertPlainText("Total Size : "+tmp1+" GB"); ui->textEditDriverDetails->insertPlainText("\n\n\n"); ui->textEditDriverDetails->insertPlainText("Available Size : "+tmp2+" GB"); statusBar()->insertWidget(1,label1,20); statusBar()->insertWidget(2,label2,20); statusBar()->insertWidget(3,label3,20); label1->setText("<font color='red'>Drive :</font>"); label2->setText("<font color='blue'>Total Size :</font>"); label3->setText("<font color='green'>Free Size :</font>"); ///QColor color()
}
@...and one more problem i am getting is that these three panes are getting created each time i click on tree item :-(
-
So, don't create them in response to such a click, but only once! In your click, you only need to set the values, not create the complete QLabel.
-
And it is exaclty what I mentiond, use
@
statusBar()->insertWidget(0,label1,20);
statusBar()->insertWidget(1,label2,20);
statusBar()->insertWidget(2,label3,20);
@from the docs:
bq. Inserts the given widget at the given index to this status bar, reparenting the widget if it isn't already a child of this QStatusBar object. If index is out of range, the widget is appended (in which case it is the actual index of the widget that is returned).
-
shall I create them in my constructor and use them in every click ?/
-
[quote author="Thomas Kennedy" date="1302608291"]shall I create them in my constructor and use them in every click ?/[/quote]
Yes. Or, better yet, update them when the selection changes, not when you click them. -
oops..my app gets hanged...
i did like this
declared .h file
@
private:
QLabel *label1;
QLabel *label2;
QLabel *label3;
@invoked and attached to statusbar in constructor
@
IDT_MainWindow::IDT_MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::IDT_MainWindow){
//...........
//.................label1=new QLabel(); label2=new QLabel(); label3=new QLabel(); statusBar()->insertWidget(0,label1,20); statusBar()->insertWidget(1,label2,20); statusBar()->insertWidget(2,label3,20);
}
@updating/displaying on treewidget item clicked
@
void IDT_MainWindow::on_treeWidgetDrives_itemClicked(QTreeWidgetItem* item, int column)
{
//...........
//...........
label1->setText("<font color='red'>Drive :</font>");
label2->setText("<font color='blue'>Total Size :</font>");
label3->setText("<font color='green'>Free Size :</font>");
}
@............please lemme know my wrong steps
-
[quote author="Thomas Kennedy" date="1302672610"]oops..my app gets hanged...
[/quote]That is way too vague. What happens exactly? What does your debugger tell you?
The snippets you posted look fine at first sight, but because they are not very complete, there is no way to tell if they trigger a problem anyway.Note that I find it weird that you set the fixed label text when clicking on an item in your tree. I was assuming you wanted to set some dynamic text based your click.
-
yes Adre..my intentions is to set the test dynamically...I just tried with that sample text with color..but why should this code causing to crash the app ??
"IDT_DEmo_UI.exe has stopped working
A Problem caused the program to stop working correctly.Windows will close the program and notify you if a solutions is available."...this is the message window with a "Close Program" button I am getting.
-
"E:\Bose\Qt playground\IDT_Demo_UI-build-desktop\debug\IDT_Demo_UI.exe exited with code 255"
..debugger report -
OK, so now, run your code through a debugger. That will tell you where the code crashed and why it did so. We cannot possibly guess based on the snippets you showed us.
-
through a debugger means with breakpoint ?
-
No, no breakpoint needed, your crash will supply that point :-)
-
I am running the app in debug mode only...after getting that app message I am not being taken to any code line...app is just getting closed !!!...how to get the appropriate trace ??
-
and also how to get get the error code description ??
-
Are you using QtCreator?
If so, run your program by pressing F5 (or pressing the green arrow with the little bug on it on the bottom left of your screen).