Page 1 of 2
[Qt]setWindowTitle() only displaying part of word
Posted: Mon Feb 14, 2011 6:37 pm
by lotios611
I'm trying to write a level editor in Qt, and have come across a little issue. When I read in my level, the name of it is an std::string. I call setWindowTitle(QString::fromStdString(levelName) and it does set the title, but it only displays part of the level's name followed by ellipsis. For example, if my level's name was Hello, the window's name would be He... I have tested outputting the level name using std::cout, and it prints fine. Is there any way to have it change the window title to display the full name of the level?
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Tue Feb 15, 2011 1:22 am
by Milch
Maybe your window is too small?
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Tue Feb 15, 2011 10:08 am
by Falco Girgis
lotios611 wrote:I'm trying to write a level editor in Qt, and have come across a little issue. When I read in my level, the name of it is an std::string. I call setWindowTitle(QString::fromStdString(levelName) and it does set the title, but it only displays part of the level's name followed by ellipsis. For example, if my level's name was Hello, the window's name would be He... I have tested outputting the level name using std::cout, and it prints fine. Is there any way to have it change the window title to display the full name of the level?
I'm sure it's something that either QT is doing for you implicitly, or the GUI environment for your OS (Windows Aero, OSX Cocoa, KDE, etc) is doing for you.
You can easily confirm this suspicion by getting the window title and qDebug()ing that bad boy. I would guess that you aren't doing anything wrong, that it happens when the name is too long, and that there is nothing you can do about it.
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Tue Feb 15, 2011 3:49 pm
by lotios611
It can't be because it's too long, because I set the window title to "Dream Team Editor" in the constructor of my custom QMainWindow class and the level's name is only "Hello."
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Tue Feb 15, 2011 4:05 pm
by Falco Girgis
lotios611 wrote:It can't be because it's too long, because I set the window title to "Dream Team Editor" in the constructor of my custom QMainWindow class and the level's name is only "Hello."
So what is the QString returned when you get the title after it has been set?
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Tue Feb 15, 2011 5:37 pm
by lotios611
After the level has been loaded, or after I set it to "Dream Team Editor"? After the level has been loaded, windowTitle() returns "Hello" and after I set it to "Dream Team Editor" it returns "Dream Team Editor."
Edit: Well, this is weird... I call setWindowTitle("Hello") and it sets the title correctly.However, when I set it using the text from my level file, it sets it to "He..."
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Thu Feb 17, 2011 5:56 pm
by lotios611
I still need help with this.
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Thu Feb 17, 2011 10:27 pm
by eatcomics
If you would be so kind as to post some code I'll try and help you, as I've been using Qt lately, and have somewhat of an understanding of it xD
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Fri Feb 18, 2011 6:09 am
by lotios611
This is how I change the title the first time:
Code: Select all
setWindowTitle("Dream Team Editor");
This is how I change the title the second time:
Code: Select all
fileName = QFileDialog::getOpenFileName();
std::fstream level(fileName.toStdString().c_str());
std::string levelName;
std::getline(level, levelName);
std::cout << levelName;
setWindowTitle(QString::fromStdString(levelName));
This is all in a class that inherits QMainWindow and the first piece of code is in the constructor and the second piece is in my map loading method.
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Fri Feb 18, 2011 9:09 am
by Arce
Hmm...
Try tossing this into your map loading method, after you set the name:
I'm thinking perhaps it's not repainting immediately, and by explicitly calling the processEvents(), it'll repaint the titlebar for ya (as changing it would be flagged as a q event of some kind internally).
Lemme know if that helps, or if I should keep digging. Sorry I missed this topic earlier.
edit: Ironically, I just googled the answer to this question, and found my own response after clicking a link to this exact topic on the first page of google. Hell yea for community!
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Fri Feb 18, 2011 9:46 am
by Arce
Actually, it seems like I am not understanding your problem. It's nothing to do with painting, but an actual problem with the window displaying the right name?
After the level has been loaded, or after I set it to "Dream Team Editor"? After the level has been loaded, windowTitle() returns "Hello" and after I set it to "Dream Team Editor" it returns "Dream Team Editor."
Edit: Well, this is weird... I call setWindowTitle("Hello") and it sets the title correctly.However, when I set it using the text from my level file, it sets it to "He..."
Hmm..Now I'm confused. Sounds like a conversion problem or something, here:
Code: Select all
setWindowTitle(QString::fromStdString(levelName));
Go ahead and add this and tell me what it says:
Code: Select all
qDebug() << QString::fromStdString(levelName);
Does it display "He..." or "Hello" to the console?
Also, is there a particular reason you're using std::String instead of QString?
I know this is a preference thing, but have you considered using Qt's built-in methods of fileIO? I find that using the q equivalents of stl always seem to work nicer within qt's framework. There's a bunch of documented "oddities" when converting from stl things to q...
I'm not home atm (posting form iphone) so this may not be the exact syntax, but try something like this and lemme know if there's any improvement:
Code: Select all
fileName = QFileDialog::getOpenFileName();
QFile level(fileName);
QTextStream stream(&level);
QString levelName;
stream >> levelName;
setWindowTitle(levelName);
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Fri Feb 18, 2011 11:50 am
by lotios611
Arce wrote:
Go ahead and add this and tell me what it says:
Code: Select all
qDebug() << QString::fromStdString(levelName);
Does it display "He..." or "Hello" to the console?
It displays "Hello".
Arce wrote:
Also, is there a particular reason you're using std::String instead of QString?
I know this is a preference thing, but have you considered using Qt's built-in methods of fileIO? I find that using the q equivalents of stl always seem to work nicer within qt's framework. There's a bunch of documented "oddities" when converting from stl things to q...
Well, I originally coded it using standard C++, so I used std::string's. When I plugged it into Qt I tried to use Qt's file IO but I couldn't figure out how to use it so I just stuck with C++'s file IO.
Code: Select all
fileName = QFileDialog::getOpenFileName();
QFile level(fileName);
QTextStream stream(&level);
QString levelName;
stream >> levelName;
setWindowTitle(levelName)
Using this code doesn't change the window title at all.
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Fri Feb 18, 2011 2:05 pm
by Falco Girgis
That isn't going to matter at all.
Within the Toolkit, all "toolkit code" is written in straight QT (QStrings, QDataTypes), but the AssetIO framework that's shared between the engine and toolkit is low level C/C++ code. We use fstreams, FILE * handles, and C/++ standard library functions all the time.
Any time a string from the AssetIO must be utilized from within QT or vice versa, we go from char * to std::string to QString and back. Never had a problem on any platform. You won't have one, either. The C/++ standard libraries are platform independent to begin with.
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Sat Feb 19, 2011 1:58 pm
by lotios611
Well, that's what I thought, but I still have no idea what's going on here...
Re: [Qt]setWindowTitle() only displaying part of word
Posted: Sat Feb 19, 2011 4:32 pm
by adikid89
post a screenshot if you will. I'd like to see how it looks like, cause it doesn't quite make sense...