[Qt]setWindowTitle() only displaying part of word

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
lotios611
Chaos Rift Regular
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

Post 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?
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Milch
Chaos Rift Junior
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

Post by Milch »

Maybe your window is too small?
Follow me on twitter!
User avatar
Falco Girgis
Elysian Shadows Team
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

Post 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. :)
User avatar
lotios611
Chaos Rift Regular
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

Post 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."
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Falco Girgis
Elysian Shadows Team
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

Post 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?
User avatar
lotios611
Chaos Rift Regular
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

Post 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..."
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
lotios611
Chaos Rift Regular
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

Post by lotios611 »

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
User avatar
eatcomics
ES Beta Backer
ES Beta Backer
Posts: 2528
Joined: Sat Mar 08, 2008 7:52 pm
Location: Illinois

Re: [Qt]setWindowTitle() only displaying part of word

Post 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
Image
User avatar
lotios611
Chaos Rift Regular
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

Post 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.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: [Qt]setWindowTitle() only displaying part of word

Post by Arce »

Hmm...

Try tossing this into your map loading method, after you set the name:

Code: Select all

qApp->processEvents();
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! ;)
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
Arce
Jealous Self-Righteous Prick
Jealous Self-Righteous Prick
Posts: 2153
Joined: Mon Jul 10, 2006 9:29 pm

Re: [Qt]setWindowTitle() only displaying part of word

Post 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);
<qpHalcy0n> decided to paint the office, now i'm high and my hands hurt
User avatar
lotios611
Chaos Rift Regular
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

Post 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.
"Why geeks like computers: unzip, strip, touch, finger, grep, mount, fsck, more, yes, fsck, fsck, fsck, umount, sleep." - Unknown
User avatar
Falco Girgis
Elysian Shadows Team
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

Post 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.
User avatar
lotios611
Chaos Rift Regular
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

Post by lotios611 »

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
User avatar
adikid89
Chaos Rift Cool Newbie
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 by adikid89 »

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
==============================================================
Image
Post Reply