[Qt]setWindowTitle() only displaying part of word
Moderator: Coders of Rage
- lotios611
- Chaos Rift Regular
- Posts: 160
- Joined: Sun Jun 14, 2009 12:05 pm
- Current Project: Game engine for the PC, PSP, and maybe more.
- Favorite Gaming Platforms: Gameboy Micro
- Programming Language of Choice: C++
[Qt]setWindowTitle() only displaying part of word
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?
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
- Milch
- Chaos Rift Junior
- Posts: 241
- Joined: Sat Jul 11, 2009 5:55 am
- Programming Language of Choice: C++
- Location: Austria, Vienna
Re: [Qt]setWindowTitle() only displaying part of word
Maybe your window is too small?
Follow me on twitter!
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: [Qt]setWindowTitle() only displaying part of word
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.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?
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.
- lotios611
- Chaos Rift Regular
- Posts: 160
- Joined: Sun Jun 14, 2009 12:05 pm
- Current Project: Game engine for the PC, PSP, and maybe more.
- Favorite Gaming Platforms: Gameboy Micro
- Programming Language of Choice: C++
Re: [Qt]setWindowTitle() only displaying part of word
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."
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: [Qt]setWindowTitle() only displaying part of word
So what is the QString returned when you get the title after it has been set?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."
- lotios611
- Chaos Rift Regular
- Posts: 160
- Joined: Sun Jun 14, 2009 12:05 pm
- Current Project: Game engine for the PC, PSP, and maybe more.
- Favorite Gaming Platforms: Gameboy Micro
- Programming Language of Choice: C++
Re: [Qt]setWindowTitle() only displaying part of word
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..."
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..."
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
- lotios611
- Chaos Rift Regular
- Posts: 160
- Joined: Sun Jun 14, 2009 12:05 pm
- Current Project: Game engine for the PC, PSP, and maybe more.
- Favorite Gaming Platforms: Gameboy Micro
- Programming Language of Choice: C++
Re: [Qt]setWindowTitle() only displaying part of word
I still need help with this.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
Re: [Qt]setWindowTitle() only displaying part of word
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
- lotios611
- Chaos Rift Regular
- Posts: 160
- Joined: Sun Jun 14, 2009 12:05 pm
- Current Project: Game engine for the PC, PSP, and maybe more.
- Favorite Gaming Platforms: Gameboy Micro
- Programming Language of Choice: C++
Re: [Qt]setWindowTitle() only displaying part of word
This is how I change the title the first time:
This is how I change the title the second time:
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.
Code: Select all
setWindowTitle("Dream Team Editor");
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));
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
Re: [Qt]setWindowTitle() only displaying part of word
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!
Try tossing this into your map loading method, after you set the name:
Code: Select all
qApp->processEvents();
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!
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
Re: [Qt]setWindowTitle() only displaying part of word
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?
Hmm..Now I'm confused. Sounds like a conversion problem or something, here:
Go ahead and add this and tell me what it says:
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:
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));
Code: Select all
qDebug() << QString::fromStdString(levelName);
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);
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
- lotios611
- Chaos Rift Regular
- Posts: 160
- Joined: Sun Jun 14, 2009 12:05 pm
- Current Project: Game engine for the PC, PSP, and maybe more.
- Favorite Gaming Platforms: Gameboy Micro
- Programming Language of Choice: C++
Re: [Qt]setWindowTitle() only displaying part of word
It displays "Hello".Arce wrote: Go ahead and add this and tell me what it says:
Does it display "He..." or "Hello" to the console?Code: Select all
qDebug() << QString::fromStdString(levelName);
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.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...
Using this code doesn't change the window title at all.Code: Select all
fileName = QFileDialog::getOpenFileName(); QFile level(fileName); QTextStream stream(&level); QString levelName; stream >> levelName; setWindowTitle(levelName)
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
- Falco Girgis
- Elysian Shadows Team
- Posts: 10294
- Joined: Thu May 20, 2004 2:04 pm
- Current Project: Elysian Shadows
- Favorite Gaming Platforms: Dreamcast, SNES, NES
- Programming Language of Choice: C/++
- Location: Studio Vorbis, AL
- Contact:
Re: [Qt]setWindowTitle() only displaying part of word
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.
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.
- lotios611
- Chaos Rift Regular
- Posts: 160
- Joined: Sun Jun 14, 2009 12:05 pm
- Current Project: Game engine for the PC, PSP, and maybe more.
- Favorite Gaming Platforms: Gameboy Micro
- Programming Language of Choice: C++
Re: [Qt]setWindowTitle() only displaying part of word
Well, that's what I thought, but I still have no idea what's going on here...
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
- adikid89
- Chaos Rift Cool Newbie
- Posts: 94
- Joined: Tue Apr 27, 2010 6:59 am
- Current Project: small tiny-mini projects
- Favorite Gaming Platforms: PC I guess...
- Programming Language of Choice: c++
Re: [Qt]setWindowTitle() only displaying part of word
post a screenshot if you will. I'd like to see how it looks like, cause it doesn't quite make sense...
My first game C++/SDL Yoshi Combat! = http://www.youtube.com/watch?v=HQ9mMBEWSZg
==============================================================
==============================================================