суббота, 24 октября 2009 г.

QTableView прокрутка строк

Понадобилось по нажатию на кнопке формы прокручивать таблицу. Т.е. заменить scrollbar.
По нажатию кнопки сверху, поднимаемся на одну строку.
По нажатию кнопки снизу, опускаемся.
У QTableView таких методов нет. Зато есть методы scrollToBottom () и scrollToTop (), наследуемые от QAbstractItemView.
Также есть метод scrollTo ( const QModelIndex &, ScrollHint ), но у QModelIndex нет переопределённых операторов ++ и --.
Идём в исходники QAbstractItemView, который наследуется QTableView и видим:

void QAbstractItemView::scrollToTop()
{
verticalScrollBar()->setValue(verticalScrollBar()->minimum());
}

Значит делаем так:
void MyClass::scrollDown()
{
int current = tvPreview->verticalScrollBar()->value();
tvPreview->verticalScrollBar()->setValue(++current);

}


void MyClass::scrollUp()
{
int current = tvPreview->verticalScrollBar()->value();
tvPreview->verticalScrollBar()->setValue(--current);
}

среда, 7 октября 2009 г.

Восстанавливаем GRUB

Если вы затёрли mbr после, скажем, установки Windows и под рукой есть LiveCD ubuntu\kubuntu, нужно выполнить следующие шаги:

1. Boot from a Live CD, like Ubuntu Live, Knoppix, Mepis, or similar. Ideally use Ubuntu 8.04 or higher as this has NTFS write support and makes life a bit easier; this isn't necessary, just handy.

2. Open a Terminal. Open a root terminal (that is, type "su" in a non-Ubuntu distro, or "sudo -i" in Ubuntu). Enter root passwords as necessary.

3. Type "grub" which makes a GRUB prompt appear.

4. Type "find /boot/grub/stage1". You'll get a response like "(hd0)" or in my case "(hd0,3)". Use whatever your computer spits out for the following lines. Note that you should have mounted the partition which has your Linux system before typing this command. (e.g. In Knoppix Live CD partitions are shown on the desktop but they're not mounted until you double-click on them or mount them manually)

5. Type "root (hd0,3)" note the space between root and (hd0,3).

6. Type "setup (hd0,3)". This is key. Other instructions say to use "(hd0)", and that's fine if you want to write GRUB to the MBR. If you want to write it to your linux root partition, then you want the number after the comma, such as "(hd0,3)".

7. Type "quit".

8. At this stage you can either restart the system and install your own bootloader, or you can continue and tell the Windows bootloader where to find GRUB which will handle booting Linux.