PDA

View Full Version : setTabStopWidth not working correctly?



Kyosaur
2nd January 2012, 06:06
Hello everyone, im making an IDE for a programming language called PAWN. I have syntax highlighting down, but one problem im having is indentation. For starters tab doesnt indent correctly, so i tried using setTabStopWidth to fix this. I was worried about how it would scale when users change fonts and font sizes though, so i looked for a way to do it in a much cleaner manner than trial and error for a single font/font size.



m_CodeEditor->setTabStopWidth(fontMetrics().width(" ") * 4);


This is what i eventually found. This was working fine for the default font, but it really doesnt seem to like when i use other custom fonts like Courier New. It should be indenting four spaces or so, but it only indenting about 2 spaces. Im not sure if i need to DO something when i set a QTextEdit's font so setTabStopWidth will work, or if the function simply doesnt work correctly. Either way, indentation is messed up with different fonts and that needs to be fixed.



My second part of the question is, how would i go about making an auto-indent like feature? Im sure its pretty simple, but i've obviously over looked it. Im not asking for code hand outs, just how i would resolve my two questions.

Kyosaur
6th January 2012, 00:07
This is me bumping my topic because i am in need of assistance, and apparently need 10 characters to submit a message. Rather than typing "bump" and be done with it im going to keep typing, simply because i am bored enough to do so. No one has so far been able to assist me on any IRC channel or forum and im not sure why. This seems relatively straight forward, and i know there are skilled programmers out there. Perhaps there is a conspiracy going on!? Or perhaps im seriously sleep deprived and am making mountians out of mole hills, either way one thing is for certain.... mountain dew time.

I hope you liked my story, even though there was a severe lack of dragons and pink assault flamignos.

Spitfire
9th January 2012, 10:25
Just take a look like aut-indent feature works in other IDEs and try to mimic that.

For example, when user hits enter previous line is investigated. If { is found at the end, indent increases, if ; is found it remains the same, if } is found it decreases.
You don't need to keep track of anything as you can figure out previous level by counting the spaces at the beggining of a line.

I'm not sure about your first questions but I liked your story :)

Kyosaur
9th January 2012, 15:16
I meant more like HOW i would indent it lol. I cant even have the USER indent the damn code correctly, so its just really frustrating.